Exemplo n.º 1
0
    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"])
Exemplo n.º 2
0
    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"])
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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"))
Exemplo n.º 7
0
    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"])
Exemplo n.º 8
0
    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"))
Exemplo n.º 9
0
    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(""))
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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"}}})
Exemplo n.º 15
0
    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",
                    }
                }
             })
Exemplo n.º 16
0
    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("")))
Exemplo n.º 17
0
 def test_has_credentials(self):
     """CloudConfig() doesn't support credentials yet."""
     with self.assertRaises(NotImplementedError):
         CloudConfig("spam", "lxd", "localhost", None, ["x"])
Exemplo n.º 18
0
 def test_has_auth_types(self):
     """CloudConfig() doesn't support auth_types yet."""
     with self.assertRaises(NotImplementedError):
         CloudConfig("spam", "lxd", "localhost", ["x"])
Exemplo n.º 19
0
 def test_missing_driver(self):
     """CloudConfig() fails when driver is empty."""
     with self.assertRaises(ValueError):
         CloudConfig("spam", "")
Exemplo n.º 20
0
    def test_empty(self):
        """CloudConfig() still works when endpoint is empty."""
        cfg = CloudConfig(u"spam", u"lxd", u"")

        self.assertIsNone(cfg.endpoint)
Exemplo n.º 21
0
 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")