Revision b555101c test/py/cfgupgrade_unittest.py

b/test/py/cfgupgrade_unittest.py
37 37
import testutils
38 38

  
39 39

  
40
def GetMinimalConfig():
41
  return {
42
    "version": constants.CONFIG_VERSION,
43
    "cluster": {
44
      "master_node": "node1-uuid"
45
    },
46
    "instances": {},
47
    "nodegroups": {},
48
    "nodes": {
49
      "node1-uuid": {
50
        "name": "node1",
51
        "uuid": "node1-uuid"
52
      }
53
    },
54
  }
55

  
56

  
40 57
def _RunUpgrade(path, dry_run, no_verify, ignore_hostname=True,
41 58
                downgrade=False):
42 59
  cmd = [sys.executable, "%s/tools/cfgupgrade" % testutils.GetSourceDir(),
......
95 112
  def testWrongHostname(self):
96 113
    self._CreateValidConfigDir()
97 114

  
98
    utils.WriteFile(self.config_path, data=serializer.DumpJson({
99
      "version": constants.CONFIG_VERSION,
100
      "cluster": {},
101
      "instances": {},
102
      "nodegroups": {},
103
      }))
115
    utils.WriteFile(self.config_path,
116
                    data=serializer.DumpJson(GetMinimalConfig()))
104 117

  
105 118
    hostname = netutils.GetHostname().name
106 119
    assert hostname != utils.ReadOneLineFile(self.ss_master_node_path)
......
111 124
  def testCorrectHostname(self):
112 125
    self._CreateValidConfigDir()
113 126

  
114
    utils.WriteFile(self.config_path, data=serializer.DumpJson({
115
      "version": constants.CONFIG_VERSION,
116
      "cluster": {},
117
      "instances": {},
118
      "nodegroups": {},
119
      }))
127
    utils.WriteFile(self.config_path,
128
                    data=serializer.DumpJson(GetMinimalConfig()))
120 129

  
121 130
    utils.WriteFile(self.ss_master_node_path,
122 131
                    data="%s\n" % netutils.GetHostname().name)
......
126 135
  def testInconsistentConfig(self):
127 136
    self._CreateValidConfigDir()
128 137
    # There should be no "config_version"
129
    cfg = {
130
      "version": 0,
131
      "cluster": {
132
        "config_version": 0,
133
        },
134
      "instances": {},
135
      "nodegroups": {},
136
      }
138
    cfg = GetMinimalConfig()
139
    cfg["version"] = 0
140
    cfg["cluster"]["config_version"] = 0
137 141
    utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
138 142
    self.assertRaises(Exception, _RunUpgrade, self.tmpdir, False, True)
139 143

  
......
150 154
  def _TestSimpleUpgrade(self, from_version, dry_run,
151 155
                         file_storage_dir=None,
152 156
                         shared_file_storage_dir=None):
153
    cluster = {}
157
    cfg = GetMinimalConfig()
158
    cfg["version"] = from_version
159
    cluster = cfg["cluster"]
154 160

  
155 161
    if file_storage_dir:
156 162
      cluster["file_storage_dir"] = file_storage_dir
157 163
    if shared_file_storage_dir:
158 164
      cluster["shared_file_storage_dir"] = shared_file_storage_dir
159 165

  
160
    cfg = {
161
      "version": from_version,
162
      "cluster": cluster,
163
      "instances": {},
164
      "nodegroups": {},
165
      }
166 166
    self._TestUpgradeFromData(cfg, dry_run)
167 167

  
168 168
  def _TestUpgradeFromData(self, cfg, dry_run):

Also available in: Unified diff