@@ -3,6 +3,7 @@ package master
3
3
import (
4
4
"testing"
5
5
6
+ osconfigapi "github.com/openshift/origin/pkg/cmd/server/api"
6
7
networkapi "github.com/openshift/origin/pkg/network/apis/network"
7
8
"github.com/openshift/origin/pkg/network/common"
8
9
)
@@ -85,7 +86,10 @@ func Test_clusterNetworkChanged(t *testing.T) {
85
86
expectChanged = true
86
87
}
87
88
88
- changed , err := clusterNetworkChanged (& newCN , & origCN )
89
+ networkConfig := osconfigapi.MasterNetworkConfig {
90
+ ServiceNetworkCIDR : newCN .ServiceNetwork ,
91
+ }
92
+ changed , err := clusterNetworkChanged (& newCN , & origCN , networkConfig )
89
93
if changed != expectChanged {
90
94
t .Fatalf ("unexpected result (%t instead of %t) on %q: %s -> %s" , changed , expectChanged , test .name , common .ClusterNetworkToString (& origCN ), common .ClusterNetworkToString (& newCN ))
91
95
}
@@ -94,3 +98,39 @@ func Test_clusterNetworkChanged(t *testing.T) {
94
98
}
95
99
}
96
100
}
101
+
102
+ func Test_clusterNetworkChanged_BadCIDR (t * testing.T ) {
103
+ badCN := networkapi.ClusterNetwork {
104
+ ClusterNetworks : []networkapi.ClusterNetworkEntry {{CIDR : "10.128.1.0/14" , HostSubnetLength : 10 }},
105
+ ServiceNetwork : "172.30.1.0/16" ,
106
+ PluginName : "redhat/openshift-ovs-subnet" ,
107
+ }
108
+ correctedCN := networkapi.ClusterNetwork {
109
+ ClusterNetworks : []networkapi.ClusterNetworkEntry {{CIDR : "10.128.0.0/14" , HostSubnetLength : 10 }},
110
+ ServiceNetwork : "172.30.0.0/16" ,
111
+ PluginName : "redhat/openshift-ovs-subnet" ,
112
+ }
113
+ badNetworkConfig := osconfigapi.MasterNetworkConfig {
114
+ ServiceNetworkCIDR : "172.30.1.0/16" ,
115
+ }
116
+
117
+ // Older releases would store bad CIDR values into default ClusterNetwork.
118
+ // Current master will always construct a corrected ClusterNetwork; this should
119
+ // be reported as changed but not an error (so the etcd value will get updated).
120
+ changed , err := clusterNetworkChanged (& correctedCN , & badCN , badNetworkConfig )
121
+ if ! changed {
122
+ t .Fatalf ("ClusterNetwork upgrade from bad CIDR to corrected was not considered a change" )
123
+ }
124
+ if err != nil {
125
+ t .Fatalf ("ClusterNetwork upgrade from bad CIDR to corrected was considered an error: %v" , err )
126
+ }
127
+
128
+ // Should work after the etcd value is corrected even if master-config isn't
129
+ changed , err = clusterNetworkChanged (& correctedCN , & correctedCN , badNetworkConfig )
130
+ if changed {
131
+ t .Fatalf ("ClusterNetwork unexpectedly considered changed" )
132
+ }
133
+ if err != nil {
134
+ t .Fatalf ("ClusterNetwork unexpectedly considered an error: %v" , err )
135
+ }
136
+ }
0 commit comments