예제 #1
0
    def test_conversions(self):
        """FakeJuju() doesn't convert the type of any value."""
        juju_str = FakeJuju("/fake-juju", "1.25.6", "/x", "/y",
                            Failures("/..."))
        juju_unicode = FakeJuju(u"/fake-juju", u"1.25.6", u"/x", u"/y",
                                Failures(u"/..."))

        for name in ('filename version datadir logsdir'.split()):
            self.assertIsInstance(getattr(juju_str, name), str)
            self.assertIsInstance(getattr(juju_unicode, name), unicode)
예제 #2
0
    def test_cli_full(self):
        """FakeJuju.cli() works correctly when given all args."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")
        cli = juju.cli("/y", {"SPAM": "eggs"})

        self.assertEqual(
            cli._exe,
            Executable(
                "/fake-juju", {
                    "SPAM": "eggs",
                    "FAKE_JUJU_DATA_DIR": "/x",
                    "FAKE_JUJU_FAILURES": "/x/juju-failures",
                    "FAKE_JUJU_LOGS_DIR": "/x",
                    "JUJU_HOME": "/y",
                }),
        )
예제 #3
0
    def test_cli_juju1(self):
        """FakeJuju.cli() works correctly for Juju 1.x."""
        juju = FakeJuju.from_version("1.25.6", "/x")
        cli = juju.cli("/y")

        self.assertEqual(cli._exe.envvars["JUJU_HOME"], "/y")
        self.assertIsInstance(cli._juju, _juju1.CLIHooks)
예제 #4
0
    def test_cli_juju2(self):
        """FakeJuju.cli() works correctly for Juju 2.x."""
        juju = FakeJuju.from_version("2.0.0", "/x")
        cli = juju.cli("/y")

        self.assertEqual(cli._exe.envvars["JUJU_DATA"], "/y")
        self.assertIsInstance(cli._juju, _juju2.CLIHooks)
예제 #5
0
    def test_is_bootstrapped_false(self):
        """FakeJuju.is_bootstrapped() returns False if the fifo is gone."""
        with tempdir() as datadir:
            fakejuju = FakeJuju.from_version("1.25.6", datadir)
            result = fakejuju.is_bootstrapped()

        self.assertFalse(result)
예제 #6
0
    def test_cli_minimal(self):
        """FakeJuju.cli() works correctly when given minimal args."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")
        cli = juju.cli("/y")

        self.assertEqual(
            cli._exe,
            Executable(
                "/fake-juju",
                dict(
                    os.environ, **{
                        "FAKE_JUJU_DATA_DIR": "/x",
                        "FAKE_JUJU_FAILURES": "/x/juju-failures",
                        "FAKE_JUJU_LOGS_DIR": "/x",
                        "JUJU_HOME": "/y",
                    })),
        )
예제 #7
0
    def test_minimal(self):
        """FakeJuju() works correctly when given minimal args."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/my/juju/home")

        self.assertEqual(juju.filename, "/fake-juju")
        self.assertEqual(juju.version, "1.25.6")
        self.assertEqual(juju.datadir, "/my/juju/home")
        self.assertEqual(juju.logsdir, "/my/juju/home")
        self.assertEqual(juju.failures.filename, "/my/juju/home/juju-failures")
예제 #8
0
    def test_is_bootstrapped_true(self):
        """FakeJuju.is_bootstrapped() returns True if the fifo file exists."""
        with tempdir() as datadir:
            fakejuju = FakeJuju.from_version("1.25.6", datadir)
            with open(fakejuju.fifo, "w"):
                pass
            result = fakejuju.is_bootstrapped()

        self.assertTrue(result)
예제 #9
0
    def test_from_version_full(self):
        """FakeJuju.from_version() works correctly when given all args."""
        juju = FakeJuju.from_version("1.25.6", "/a/juju/home", "/logs/dir",
                                     "/failures/dir", "/bin/dir")

        self.assertEqual(juju.filename, "/bin/dir/fake-juju-1.25.6")
        self.assertEqual(juju.version, "1.25.6")
        self.assertEqual(juju.datadir, "/a/juju/home")
        self.assertEqual(juju.logsdir, "/logs/dir")
        self.assertEqual(juju.failures.filename, "/failures/dir/juju-failures")
예제 #10
0
    def test_full(self):
        """FakeJuju() works correctly when given all args."""
        datadir = "/my/juju/home"
        failures = Failures(datadir)
        juju = FakeJuju("/fake-juju", "1.25.6", datadir, "/some/logs",
                        failures)

        self.assertEqual(juju.filename, "/fake-juju")
        self.assertEqual(juju.version, "1.25.6")
        self.assertEqual(juju.datadir, datadir)
        self.assertEqual(juju.logsdir, "/some/logs")
        self.assertIs(juju.failures, failures)
예제 #11
0
    def test_infofile(self):
        """FakeJuju.logfile returns the path to the fake-juju info file."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")

        self.assertEqual(juju.infofile, "/x/fakejuju")
예제 #12
0
    def test_bootstrap(self):
        """FakeJuju.bootstrap() bootstraps from scratch using fake-juju."""
        expected = txjuju.cli.APIInfo(
            endpoints=['localhost:12727'],
            user='******',
            password='******',
            model_uuid='deadbeef-0bad-400d-8000-4b1d0d06f00d',
        )
        version = "1.25.6"
        with tempdir() as testdir:
            bindir = os.path.join(testdir, "bin")
            datadir = os.path.join(testdir, "fakejuju")
            cfgdir = os.path.join(testdir, ".juju")

            logfilename = write_fakejuju_script(version, bindir, datadir,
                                                cfgdir, expected)
            fakejuju = FakeJuju.from_version(version, cfgdir, bindir=bindir)

            cli, api_info = fakejuju.bootstrap("spam", cfgdir, "secret")

            files = []
            files.extend(
                os.path.join(os.path.basename(datadir), name)
                for name in os.listdir(datadir))
            files.extend(
                os.path.join(os.path.basename(cfgdir), name)
                for name in os.listdir(cfgdir))
            with open(os.path.join(cfgdir, "environments.yaml")) as envfile:
                data = envfile.read()

            cli.destroy_controller()
            with open(logfilename) as logfile:
                calls = [line.strip() for line in logfile]

        self.maxDiff = None
        self.assertEqual(api_info, {
            'controller': expected,
            None: expected._replace(model_uuid=None),
        })
        subcommands = []
        for call in calls:
            args = call.split()
            self.assertEqual(os.path.basename(args[0]), "fake-juju-" + version)
            subcommands.append(args[1])
        self.assertEqual(subcommands, [
            "bootstrap",
            "api-info",
            "destroy-environment",
        ])
        self.assertItemsEqual(files, [
            '.juju/environments',
            '.juju/environments.yaml',
            'fakejuju/cert.ca',
            'fakejuju/fake-juju.log',
            'fakejuju/fakejuju',
            'fakejuju/fifo',
        ])
        self.assertEqual(
            yaml.load(data), {
                "environments": {
                    "spam": {
                        "admin-secret": "secret",
                        "default-series": "trusty",
                        "type": "dummy",
                    },
                },
            })
예제 #13
0
 def test_missing_filename(self):
     """FakeJuju() fails if filename is None or empty."""
     with self.assertRaises(ValueError):
         FakeJuju(None, "1.25.6", "/my/juju/home")
     with self.assertRaises(ValueError):
         FakeJuju("", "1.25.6", "/my/juju/home")
예제 #14
0
 def test_missing_version(self):
     """FakeJuju() fails if version is None or empty."""
     with self.assertRaises(ValueError):
         FakeJuju("/fake-juju", None, "/my/juju/home")
     with self.assertRaises(ValueError):
         FakeJuju("/fake-juju", "", "/my/juju/home")
예제 #15
0
 def test_missing_datadir(self):
     """FakeJuju() fails if datadir is None or empty."""
     with self.assertRaises(ValueError):
         FakeJuju("/fake-juju", "1.25.6", None)
     with self.assertRaises(ValueError):
         FakeJuju("/fake-juju", "1.25.6", "")
예제 #16
0
    def test_logfile(self):
        """FakeJuju.logfile returns the path to the fake-juju log file."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x", "/some/logs")

        self.assertEqual(juju.logfile, "/some/logs/fake-juju.log")
예제 #17
0
    def test_cacertfile(self):
        """FakeJuju.cacertfile returns the path to the Juju API cert."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")

        self.assertEqual(juju.cacertfile, "/x/cert.ca")
예제 #18
0
    def test_is_bootstrapped_datadir_missing(self):
        """FakeJuju.is_bootstrapped() returns False if the data dir is gone."""
        fakejuju = FakeJuju.from_version("1.25.6", "/tmp/fakejuju-no-exist")
        result = fakejuju.is_bootstrapped()

        self.assertFalse(result)
예제 #19
0
    def test_fifo(self):
        """FakeJuju.logfile returns the path to the fake-juju fifo."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")

        self.assertEqual(juju.fifo, "/x/fifo")