Exemplo n.º 1
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",
                    }
                }
             })
Exemplo n.º 2
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
Exemplo n.º 3
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.º 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": {}})
Exemplo n.º 5
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.º 6
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.º 7
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": {}})
Exemplo n.º 8
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",
                    }
                }
             })
Exemplo n.º 9
0
 def test_from_info_missing_cloud_name(self):
     """ControllerConfig.from_info() fails if cloud_name is empty."""
     with self.assertRaises(ValueError):
         ControllerConfig.from_info("spam", "lxd", "")
Exemplo n.º 10
0
 def test_from_info_missing_driver(self):
     """ControllerConfig.from_info() fails if driver is None or empty."""
     with self.assertRaises(ValueError):
         ControllerConfig.from_info("spam", None)
     with self.assertRaises(ValueError):
         ControllerConfig.from_info("spam", "")
Exemplo n.º 11
0
 def test_from_info_missing_name(self):
     """ControllerConfig.from_info() fails if name is None or empty."""
     with self.assertRaises(ValueError):
         ControllerConfig.from_info(None, "lxd")
     with self.assertRaises(ValueError):
         ControllerConfig.from_info("", "lxd")
Exemplo n.º 12
0
    def test_from_info_conversions(self):
        """ControllerConfig.from_info() converts str to unicode."""
        cfg = ControllerConfig.from_info(
            "spam", "lxd", "my-lxd", "xenial", "sekret")

        self.assertEqual(cfg.name, u"spam")