コード例 #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"])
コード例 #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"])
コード例 #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)
コード例 #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))
コード例 #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))
コード例 #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"))
コード例 #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"])
コード例 #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"))
コード例 #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(""))
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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"}}})
コード例 #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",
                    }
                }
             })
コード例 #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("")))
コード例 #17
0
 def test_has_credentials(self):
     """CloudConfig() doesn't support credentials yet."""
     with self.assertRaises(NotImplementedError):
         CloudConfig("spam", "lxd", "localhost", None, ["x"])
コード例 #18
0
 def test_has_auth_types(self):
     """CloudConfig() doesn't support auth_types yet."""
     with self.assertRaises(NotImplementedError):
         CloudConfig("spam", "lxd", "localhost", ["x"])
コード例 #19
0
 def test_missing_driver(self):
     """CloudConfig() fails when driver is empty."""
     with self.assertRaises(ValueError):
         CloudConfig("spam", "")
コード例 #20
0
    def test_empty(self):
        """CloudConfig() still works when endpoint is empty."""
        cfg = CloudConfig(u"spam", u"lxd", u"")

        self.assertIsNone(cfg.endpoint)
コード例 #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")