Пример #1
0
 def populate_cfgdir(self, name):
     """Write a basic Juju config to self.cfgdir."""
     controller = ControllerConfig.from_info(
         name, "lxd", "my-lxd", "xenial", "pw")
     cfg = Config(controller)
     cfg.write(self.cfgdir, self.version)
     return cfg
Пример #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_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"])
Пример #4
0
    def test_write_one_full(self):
        """Config.write() works fine for Juju 2.x if there is only one
        fully-populated ControllerConfig."""
        cfg = Config(ControllerConfig.from_info(
            "spam", "lxd", "my-lxd", "xenial", "pw"))
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertEquals(
            bootstraps,
            {"spam": os.path.join(self.cfgdir, "bootstrap-spam.yaml"),
             })
        self.assertEqual(
            sorted(os.listdir(self.cfgdir)),
            ["bootstrap-spam.yaml",
             "clouds.yaml",
             "credentials.yaml",
             ])
        self.assert_cfgfile(
            "bootstrap-spam.yaml",
            {"default-series": "xenial",
             })
        self.assert_cfgfile(
            "clouds.yaml",
            {"clouds": {"my-lxd": {
                "type": "lxd",
                }}})
        self.assert_cfgfile("credentials.yaml", {"credentials": {}})
Пример #5
0
    def test_write_multiple(self):
        """Config.write() works fine for Juju 1.x if there are multiple
        controller configs."""
        cfg = Config(
            ControllerConfig.from_info(
                "spam", "lxd", "my-lxd", "xenial", "sekret"),
            ControllerConfig.from_info(
                "eggs", "maas", "maas", "trusty", "pw"),
            )
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertIsNone(bootstraps)
        self.assertEqual(os.listdir(self.cfgdir), ["environments.yaml"])
        self.assert_cfgfile(
            "environments.yaml",
            {"environments": {
                "spam": {
                    "type": "lxd",
                    "default-series": "xenial",
                    "admin-secret": "sekret",
                    },
                "eggs": {
                    "type": "maas",
                    "default-series": "trusty",
                    "admin-secret": "pw",
                    }
                }
             })
Пример #6
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"])
Пример #7
0
    def test_write_none(self):
        """Config.write() works fine for Juju 1.x if there aren't any
        controller configs."""
        cfg = Config()
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertIsNone(bootstraps)
        self.assertEqual(os.listdir(self.cfgdir), ["environments.yaml"])
        self.assert_cfgfile("environments.yaml", {})
Пример #8
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"}}})
Пример #9
0
    def test_write_none(self):
        """Config.write() works fine for Juju 2.x if there aren't any
        controller configs."""
        cfg = Config()
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertEqual(bootstraps, {})
        self.assertEqual(
            sorted(os.listdir(self.cfgdir)),
            ["clouds.yaml", "credentials.yaml"],
            )
        self.assert_cfgfile("clouds.yaml", {"clouds": {}})
        self.assert_cfgfile("credentials.yaml", {"credentials": {}})
Пример #10
0
    def test_write_one_minimal(self):
        """Config.write() works fine for Juju 1.x if there is only one
        partially-populated ControllerConfig."""
        cfg = Config(
            ControllerConfig.from_info("spam", "lxd", "my-lxd", "", ""))
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertIsNone(bootstraps)
        self.assertEqual(os.listdir(self.cfgdir), ["environments.yaml"])
        self.assert_cfgfile(
            "environments.yaml",
            {"environments": {
                "spam": {
                    "type": "lxd",
                    }
                }
             })
Пример #11
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",
                    }
                }
             })
Пример #12
0
    def test_write_multiple(self):
        """Config.write() works fine for Juju 2.x if there are multiple
        controller configs."""
        cfg = Config(
            ControllerConfig.from_info(
                "spam", "lxd", "my-lxd", "xenial", "sekret"),
            ControllerConfig.from_info(
                "eggs", "maas", "maas", "trusty", "pw"),
            )
        bootstraps = cfg.write(self.cfgdir, self.VERSION)

        self.assertEquals(
            bootstraps,
            {"spam": os.path.join(self.cfgdir, "bootstrap-spam.yaml"),
             "eggs": os.path.join(self.cfgdir, "bootstrap-eggs.yaml"),
             })
        self.assertEqual(
            sorted(os.listdir(self.cfgdir)),
            ["bootstrap-eggs.yaml",
             "bootstrap-spam.yaml",
             "clouds.yaml",
             "credentials.yaml",
             ])
        self.assert_cfgfile(
            "bootstrap-eggs.yaml",
            {"default-series": "trusty",
             })
        self.assert_cfgfile(
            "bootstrap-spam.yaml",
            {"default-series": "xenial",
             })
        self.assert_cfgfile(
            "clouds.yaml",
            {"clouds": {
                "my-lxd": {
                    "type": "lxd",
                    },
                "maas": {
                    "type": "maas",
                    },
                },
             })
        self.assert_cfgfile("credentials.yaml", {"credentials": {}})