def test_write_cfgdir_missing(self): """Config.write() creates the config dir if it is missing.""" cfgdir = os.path.join(self.cfgdir, "one", "two", "three") cfg = Config(ControllerConfig("eggs", CloudConfig("maas"))) cfg.write(cfgdir, self.version, clobber=True) self.assertEqual(os.listdir(cfgdir), ["environments.yaml"])
def test_write_clobber_no_collision(self): """Config.write() behaves like normal if clobber is True and the config files aren't there already.""" cfg = Config(ControllerConfig("eggs", CloudConfig("maas"))) cfg.write(self.cfgdir, self.version, clobber=True) self.assertEqual(os.listdir(self.cfgdir), ["environments.yaml"])
def test_missing_name(self): """ControllerConfig() fails if name is None or empty.""" cloud = CloudConfig("lxd") with self.assertRaises(ValueError): ControllerConfig(None, cloud) with self.assertRaises(ValueError): ControllerConfig("", cloud)
def test_conversions(self): """ControllerConfig() converts str to unicode.""" cloud = CloudConfig("lxd") bootstrap = BootstrapConfig("xenial") cfg = ControllerConfig("spam", cloud, bootstrap) self.assertEqual(cfg, (u"spam", cloud, bootstrap))
def test_full(self): """ControllerConfig() works when given all args.""" cloud = CloudConfig("my-lxd", "lxd", "https://localhost:8080") bootstrap = BootstrapConfig("xenial", "sekret") cfg = ControllerConfig(u"spam", cloud, bootstrap) self.assertEqual(cfg, (u"spam", cloud, bootstrap))
def test_from_info_minimal(self): """ControllerConfig.from_info() works when given minimal args.""" cfg = ControllerConfig.from_info(u"spam", u"lxd") self.assertEqual(cfg.name, u"spam") self.assertEqual(cfg.cloud, CloudConfig(u"spam-lxd", u"lxd")) self.assertEqual(cfg.bootstrap, BootstrapConfig(u"trusty"))
def test_write_no_clobber_no_collision(self): """Config.write() works fine if clobber is False and no config files are already there.""" cfg = Config(ControllerConfig("eggs", CloudConfig("maas"))) cfg.write(self.cfgdir, self.version, clobber=False) self.assertEqual(os.listdir(self.cfgdir), ["environments.yaml"])
def test_from_info_full(self): """ControllerConfig.from_info() works when given all args.""" cfg = ControllerConfig.from_info( u"spam", u"lxd", u"my-lxd", u"xenial", u"sekret") self.assertEqual(cfg.name, u"spam") self.assertEqual(cfg.cloud, CloudConfig(u"my-lxd", u"lxd")) self.assertEqual(cfg.bootstrap, BootstrapConfig(u"xenial", u"sekret"))
def test_from_info_empty(self): """ControllerConfig.from_info() still works when default_series and admin_secret are empty strings.""" cfg = ControllerConfig.from_info(u"spam", u"lxd", u"my-lxd", u"", u"") self.assertEqual(cfg.name, u"spam") self.assertEqual(cfg.cloud, CloudConfig(u"my-lxd", u"lxd")) self.assertEqual(cfg.bootstrap, BootstrapConfig(""))
def test_full(self): """CloudConfig() works when given all args.""" cfg = CloudConfig(u"spam", u"lxd", u"localhost:8080", None, None) self.assertEqual(cfg.name, u"spam") self.assertEqual(cfg.driver, u"lxd") self.assertEqual(cfg.endpoint, u"localhost:8080") self.assertIsNone(cfg.auth_types) self.assertIsNone(cfg.credentials)
def test_bootstrap_iterable(self): """ControllerConfig() supports bootstrap as an iterable.""" cloud = CloudConfig("lxd") bootstrap = BootstrapConfig("xenial") cfg1 = ControllerConfig("spam", cloud, tuple(bootstrap)) cfg2 = ControllerConfig("spam", cloud, list(bootstrap)) self.assertEqual(cfg1.cloud, cloud) self.assertEqual(cfg2.cloud, cloud)
def test_conversions(self): """CloudConfig() converts str to unicode.""" cfg = CloudConfig("spam", "lxd", "localhost:8080") self.assertEqual(cfg.name, u"spam") self.assertEqual(cfg.driver, u"lxd") self.assertEqual(cfg.endpoint, u"localhost:8080") self.assertIsNone(cfg.auth_types) self.assertIsNone(cfg.credentials)
def test_minimal(self): """CloudConfig() works when given minimal args.""" cfg = CloudConfig(u"lxd") self.assertEqual(cfg.name, u"lxd") self.assertEqual(cfg.driver, u"lxd") self.assertIsNone(cfg.endpoint) self.assertIsNone(cfg.auth_types) self.assertIsNone(cfg.credentials)
def test_write_clobber_collision(self): """Config.write() overwrites config files if clobber is True.""" self.populate_cfgdir("spam") cfg = Config(ControllerConfig( "eggs", CloudConfig("maas"), BootstrapConfig(""))) cfg.write(self.cfgdir, self.version, clobber=True) self.assert_cfgfile( "environments.yaml", {"environments": {"eggs": {"type": "maas"}}})
def test_write_no_clobber_collision(self): """Config.write() fails if clobber is False and the config files are already there. The existing files are not changed.""" self.populate_cfgdir("spam") cfg = Config(ControllerConfig("eggs", CloudConfig("maas"))) with self.assertRaises(RuntimeError): cfg.write(self.cfgdir, self.version, clobber=False) self.assert_cfgfile( "environments.yaml", {"environments": { "spam": { "type": "lxd", "default-series": "xenial", "admin-secret": "pw", } } })
def test_minimal(self): """ControllerConfig() works when given minimal args .""" cloud = CloudConfig("lxd") cfg = ControllerConfig(u"spam", cloud) self.assertEqual(cfg, (u"spam", cloud, BootstrapConfig("")))
def test_has_credentials(self): """CloudConfig() doesn't support credentials yet.""" with self.assertRaises(NotImplementedError): CloudConfig("spam", "lxd", "localhost", None, ["x"])
def test_has_auth_types(self): """CloudConfig() doesn't support auth_types yet.""" with self.assertRaises(NotImplementedError): CloudConfig("spam", "lxd", "localhost", ["x"])
def test_missing_driver(self): """CloudConfig() fails when driver is empty.""" with self.assertRaises(ValueError): CloudConfig("spam", "")
def test_empty(self): """CloudConfig() still works when endpoint is empty.""" cfg = CloudConfig(u"spam", u"lxd", u"") self.assertIsNone(cfg.endpoint)
def test_missing_name(self): """CloudConfig() fails when name is None or empty.""" with self.assertRaises(ValueError): CloudConfig(None, "lxd") with self.assertRaises(ValueError): CloudConfig("", "lxd")