Ejemplo n.º 1
0
 def test_deploy_service_name_conflict(self):
     """Raise an error if a service name conflicts with an existing service
     """
     environment = self.config.get("firstenv")
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path, "local:sample", "beekeeper", logging.getLogger("deploy")
     )
     # deploy the service a second time to generate a name conflict
     d = deploy.deploy(
         self.config, environment, self.unbundled_repo_path, "local:sample", "beekeeper", logging.getLogger("deploy")
     )
     error = yield self.failUnlessFailure(d, ServiceStateNameInUse)
     self.assertEqual(str(error), "Service name 'beekeeper' is already in use")
Ejemplo n.º 2
0
 def test_deploy_service_name_conflict(self):
     """Raise an error if a service name conflicts with an existing service
     """
     environment = self.config.get("firstenv")
     yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                         "local:sample", "beekeeper",
                         logging.getLogger("deploy"))
     # deploy the service a second time to generate a name conflict
     d = deploy.deploy(self.config, environment, self.unbundled_repo_path,
                       "local:sample", "beekeeper",
                       logging.getLogger("deploy"))
     error = yield self.failUnlessFailure(d, ServiceStateNameInUse)
     self.assertEqual(str(error),
                      "Service name 'beekeeper' is already in use")
Ejemplo n.º 3
0
    def test_deploy(self):
        """Create service, and service unit on machine from charm"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog", logging.getLogger("deploy"), ["cpu=123"])
        topology = yield self.get_topology()

        service_id = topology.find_service_with_name("myblog")
        self.assertEqual(service_id, "service-%010d" % 0)
        exists = yield self.client.exists("/services/%s" % service_id)
        self.assertTrue(exists)

        service_state_manager = ServiceStateManager(self.client)
        service_state = yield service_state_manager.get_service_state("myblog")
        charm_id = yield service_state.get_charm_id()
        self.assertEquals(charm_id, "local:series/sample-2")
        constraints = yield service_state.get_constraints()
        expect_constraints = {
            "arch": "amd64", "cpu": 123, "mem": 512,
            "provider-type": "dummy", "ubuntu-series": "series"}
        self.assertEquals(constraints, expect_constraints)

        machine_ids = topology.get_machines()
        self.assertEqual(
            machine_ids,
            ["machine-%010d" % 0, "machine-%010d" % 1])
        exists = yield self.client.exists("/machines/%s" % machine_ids[0])
        self.assertTrue(exists)

        unit_ids = topology.get_service_units(service_id)
        self.assertEqual(unit_ids, ["unit-%010d" % 0])
        exists = yield self.client.exists("/units/%s" % unit_ids[0])
        self.assertTrue(exists)
Ejemplo n.º 4
0
    def test_deploy_multiple_units(self):
        """Create service, and service unit on machine from charm"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog", logging.getLogger("deploy"), [], num_units=5)
        topology = yield self.get_topology()

        service_id = topology.find_service_with_name("myblog")
        self.assertEqual(service_id, "service-%010d" % 0)
        exists = yield self.client.exists("/services/%s" % service_id)
        self.assertTrue(exists)

        # Verify standard placement policy - unit placed on a new machine
        machine_ids = topology.get_machines()
        self.assertEqual(
            set(machine_ids),
            set(["machine-%010d" % i for i in xrange(6)]))
        for i in xrange(6):
            self.assertTrue(
                (yield self.client.exists("/machines/%s" % machine_ids[i])))

        unit_ids = topology.get_service_units(service_id)
        self.assertEqual(
            set(unit_ids),
            set(["unit-%010d" % i for i in xrange(5)]))
        for i in xrange(5):
            self.assertTrue(
                (yield self.client.exists("/units/%s" % unit_ids[i])))
Ejemplo n.º 5
0
    def test_deploy_multiple_units(self):
        """Create service, and service unit on machine from charm"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(self.config,
                            environment,
                            self.unbundled_repo_path,
                            "local:sample",
                            "myblog",
                            logging.getLogger("deploy"),
                            num_units=5)
        topology = yield self.get_topology()

        service_id = topology.find_service_with_name("myblog")
        self.assertEqual(service_id, "service-%010d" % 0)
        exists = yield self.client.exists("/services/%s" % service_id)
        self.assertTrue(exists)

        # Verify standard placement policy - unit placed on a new machine
        machine_ids = topology.get_machines()
        self.assertEqual(set(machine_ids),
                         set(["machine-%010d" % i for i in xrange(6)]))
        for i in xrange(6):
            self.assertTrue(
                (yield self.client.exists("/machines/%s" % machine_ids[i])))

        unit_ids = topology.get_service_units(service_id)
        self.assertEqual(set(unit_ids),
                         set(["unit-%010d" % i for i in xrange(5)]))
        for i in xrange(5):
            self.assertTrue((yield
                             self.client.exists("/units/%s" % unit_ids[i])))
Ejemplo n.º 6
0
 def test_deploy_reuses_machines(self):
     """Verify that if machines are not in use, deploy uses them."""
     environment = self.config.get("firstenv")
     yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                         "local:mysql", None, logging.getLogger("deploy"))
     yield deploy.deploy(self.config, environment,
                         self.unbundled_repo_path, "local:wordpress", None,
                         logging.getLogger("deploy"))
     yield self.destroy_service("mysql")
     yield self.destroy_service("wordpress")
     yield deploy.deploy(self.config, environment,
                         self.unbundled_repo_path, "local:wordpress", None,
                         logging.getLogger("deploy"))
     yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                         "local:mysql", None, logging.getLogger("deploy"))
     yield self.assert_machine_assignments("wordpress", [1])
     yield self.assert_machine_assignments("mysql", [2])
Ejemplo n.º 7
0
 def test_deploy_no_service_name_short_charm_name(self):
     """Uses charm name as service name if possible."""
     environment = self.config.get("firstenv")
     yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                         "local:sample", None, logging.getLogger("deploy"))
     service = yield ServiceStateManager(
         self.client).get_service_state("sample")
     self.assertEqual(service.service_name, "sample")
Ejemplo n.º 8
0
 def test_deploy_no_service_name_short_charm_name(self):
     """Uses charm name as service name if possible."""
     environment = self.config.get("firstenv")
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path, "local:sample", None, logging.getLogger("deploy")
     )
     service = yield ServiceStateManager(self.client).get_service_state("sample")
     self.assertEqual(service.service_name, "sample")
Ejemplo n.º 9
0
 def test_deploy_reuses_machines(self):
     """Verify that if machines are not in use, deploy uses them."""
     environment = self.config.get("firstenv")
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path, "local:mysql",
         None, logging.getLogger("deploy"), [])
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path,
         "local:wordpress", None, logging.getLogger("deploy"), [])
     yield self.destroy_service("mysql")
     yield self.destroy_service("wordpress")
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path,
         "local:wordpress", None, logging.getLogger("deploy"), [])
     yield deploy.deploy(
         self.config, environment, self.unbundled_repo_path, "local:mysql",
         None, logging.getLogger("deploy"), [])
     yield self.assert_machine_assignments("wordpress", [1])
     yield self.assert_machine_assignments("mysql", [2])
Ejemplo n.º 10
0
    def test_deploy_sends_environment(self):
        """Uses charm name as service name if possible."""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            None, logging.getLogger("deploy"), [])

        env_state_manager = EnvironmentStateManager(self.client)
        env_config = yield env_state_manager.get_config()

        self.assertEquals(yaml.load(env_config.serialize("firstenv")),
                          yaml.load(self.config.serialize("firstenv")))
Ejemplo n.º 11
0
    def test_deploy_sends_environment(self):
        """Uses charm name as service name if possible."""
        environment = self.config.get("firstenv")

        yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                            "local:sample", None, logging.getLogger("deploy"))

        env_state_manager = EnvironmentStateManager(self.client)
        env_config = yield env_state_manager.get_config()

        self.assertEquals(yaml.load(env_config.serialize("firstenv")),
                          yaml.load(self.config.serialize("firstenv")))
Ejemplo n.º 12
0
    def test_deploy_adds_peer_relations(self):
        """Deploy automatically adds a peer relations."""
        environment = self.config.get("firstenv")
        yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                            "local:riak", None, logging.getLogger("deploy"))

        service_manager = ServiceStateManager(self.client)
        service_state = yield service_manager.get_service_state("riak")
        relation_manager = RelationStateManager(self.client)
        relations = yield relation_manager.get_relations_for_service(
            service_state)
        self.assertEqual(len(relations), 1)
        self.assertEqual(relations[0].relation_name, "ring")
Ejemplo n.º 13
0
    def test_deploy_adds_peer_relations(self):
        """Deploy automatically adds a peer relations."""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:riak", None, logging.getLogger("deploy")
        )

        service_manager = ServiceStateManager(self.client)
        service_state = yield service_manager.get_service_state("riak")
        relation_manager = RelationStateManager(self.client)
        relations = yield relation_manager.get_relations_for_service(service_state)
        self.assertEqual(len(relations), 1)
        self.assertEqual(relations[0].relation_name, "ring")
Ejemplo n.º 14
0
    def test_deploy_with_bad_config(self):
        """Valid config options should be available to the deployed
        service."""
        config_file = self.makeFile(
            yaml.dump(dict(otherservice=dict(application_file="foo"))))
        environment = self.config.get("firstenv")

        failure = deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog", logging.getLogger("deploy"), [], config_file)
        error = yield self.assertFailure(failure, ServiceConfigValueError)
        self.assertIn(
            "Expected a YAML dict with service name ('myblog').", str(error))
Ejemplo n.º 15
0
    def test_deploy_with_bad_config(self):
        """Valid config options should be available to the deployed
        service."""
        config_file = self.makeFile(
            yaml.dump(dict(otherservice=dict(application_file="foo"))))
        environment = self.config.get("firstenv")

        failure = deploy.deploy(self.config, environment,
                                self.unbundled_repo_path,
                                "local:sample", "myblog",
                                logging.getLogger("deploy"), config_file)
        error = yield self.assertFailure(failure, ServiceConfigValueError)
        self.assertIn("Expected a YAML dict with service name ('myblog').",
                      str(error))
Ejemplo n.º 16
0
    def test_deploy_upgrade(self):
        """A charm can be deployed and get the latest version"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog", logging.getLogger("deploy"), [])

        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog2", logging.getLogger("deploy"), [], upgrade=True)

        services = ServiceStateManager(self.client)
        service1 = yield services.get_service_state("myblog")
        s1_charm_id = yield service1.get_charm_id()

        service2 = yield services.get_service_state("myblog2")
        s2_charm_id = yield service2.get_charm_id()

        self.assertNotEqual(s1_charm_id, s2_charm_id)

        charms = CharmStateManager(self.client)
        charm1 = yield charms.get_charm_state(s1_charm_id)
        charm2 = yield charms.get_charm_state(s2_charm_id)
        self.assertEqual(charm1.revision + 1, charm2.revision)
Ejemplo n.º 17
0
    def test_deploy_with_invalid_config(self):
        """Can't deploy with config that doesn't pass charm validation."""
        config_file = self.makeFile(
            yaml.dump(dict(myblog=dict(application_file="foo"))))
        environment = self.config.get("firstenv")

        failure = deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample",
            "myblog", logging.getLogger("deploy"), [], config_file)
        error = yield self.assertFailure(failure, ServiceConfigValueError)
        self.assertIn(
            "application_file is not a valid configuration option",
            str(error))
        yield self.assertFailure(
            ServiceStateManager(self.client).get_service_state("myblog"),
            ServiceStateNotFound)
Ejemplo n.º 18
0
    def test_deploy_with_default_config(self):
        """Valid config options should be available to the deployed
        service."""
        environment = self.config.get("firstenv")

        # Here we explictly pass no config file but the services
        # associated config.yaml defines default which we expect to
        # find anyway.
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:dummy",
            "myblog", logging.getLogger("deploy"), [], None)

        # Verify that options in the yaml are available as state after
        # the deploy call (successfully applied)
        service = yield ServiceStateManager(
            self.client).get_service_state("myblog")
        config = yield service.get_config()
        self.assertEqual(config["title"], "My Title")
Ejemplo n.º 19
0
    def test_deploy_with_default_config(self):
        """Valid config options should be available to the deployed
        service."""
        environment = self.config.get("firstenv")

        # Here we explictly pass no config file but the services
        # associated config.yaml defines default which we expect to
        # find anyway.
        yield deploy.deploy(self.config, environment,
                            self.unbundled_repo_path, "local:dummy", "myblog",
                            logging.getLogger("deploy"), None)

        # Verify that options in the yaml are available as state after
        # the deploy call (successfully applied)
        service = yield ServiceStateManager(
            self.client).get_service_state("myblog")
        config = yield service.get_config()
        self.assertEqual(config["title"], "My Title")
Ejemplo n.º 20
0
    def test_deploy_upgrade_remote(self):
        """The upgrade option is invalid with a remote charm."""
        repo = self.mocker.mock(RemoteCharmRepository)
        repo.type
        self.mocker.result("store")
        resolve = self.mocker.replace("juju.control.deploy.resolve")
        resolve("cs:sample", None, "series")
        self.mocker.result((repo, CharmURL.infer("cs:sample", "series")))
        repo.find(MATCH(lambda x: isinstance(x, CharmURL)))
        self.mocker.result(CharmDirectory(self.sample_dir1))
        self.mocker.replay()

        environment = self.config.get("firstenv")
        error = yield self.assertFailure(deploy.deploy(
            self.config, environment, None, "cs:sample",
            "myblog", logging.getLogger("deploy"), [], upgrade=True),
            CharmError)
        self.assertIn("Only local directory charms can be upgraded on deploy",
                      str(error))
Ejemplo n.º 21
0
    def test_deploy_upgrade_bundle(self):
        """The upgrade option is invalid with a charm bundle."""
        # bundle sample charms
        output = self.capture_logging("deploy")
        CharmDirectory(self.sample_dir1).make_archive(
            os.path.join(self.bundled_repo_path, "series", "old.charm"))
        CharmDirectory(self.sample_dir2).make_archive(
            os.path.join(self.bundled_repo_path, "series", "new.charm"))

        environment = self.config.get("firstenv")

        error = yield self.assertFailure(
            deploy.deploy(
                self.config, environment,
                self.bundled_repo_path, "local:sample",
                "myblog", logging.getLogger("deploy"), [], upgrade=True),
            CharmError)
        self.assertIn("Searching for charm", output.getvalue())
        self.assertIn("Only local directory charms can be upgraded on deploy",
                      str(error))
Ejemplo n.º 22
0
    def test_deploy_with_config(self):
        """Valid config options should be available to the deployed
        service."""
        config_file = self.makeFile(
            yaml.dump(dict(myblog=dict(outlook="sunny", username="******"))))
        environment = self.config.get("firstenv")

        yield deploy.deploy(self.config, environment,
                            self.unbundled_repo_path, "local:dummy", "myblog",
                            logging.getLogger("deploy"), config_file)

        # Verify that options in the yaml are available as state after
        # the deploy call (successfully applied)
        service = yield ServiceStateManager(
            self.client).get_service_state("myblog")
        config = yield service.get_config()
        self.assertEqual(config["outlook"], "sunny")
        self.assertEqual(config["username"], "tester01")
        # a default value from the config.yaml
        self.assertEqual(config["title"], "My Title")
Ejemplo n.º 23
0
    def test_deploy_with_config(self):
        """Valid config options should be available to the deployed
        service."""
        config_file = self.makeFile(yaml.dump(dict(
                    myblog=dict(outlook="sunny",
                                username="******"))))
        environment = self.config.get("firstenv")

        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:dummy",
            "myblog", logging.getLogger("deploy"), [], config_file)

        # Verify that options in the yaml are available as state after
        # the deploy call (successfully applied)
        service = yield ServiceStateManager(
            self.client).get_service_state("myblog")
        config = yield service.get_config()
        self.assertEqual(config["outlook"], "sunny")
        self.assertEqual(config["username"], "tester01")
        # a default value from the config.yaml
        self.assertEqual(config["title"], "My Title")
Ejemplo n.º 24
0
    def test_deploy(self):
        """Create service, and service unit on machine from charm"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(
            self.config, environment, self.unbundled_repo_path, "local:sample", "myblog", logging.getLogger("deploy")
        )
        topology = yield self.get_topology()

        service_id = topology.find_service_with_name("myblog")
        self.assertEqual(service_id, "service-%010d" % 0)
        exists = yield self.client.exists("/services/%s" % service_id)
        self.assertTrue(exists)

        machine_ids = topology.get_machines()
        self.assertEqual(machine_ids, ["machine-%010d" % 0, "machine-%010d" % 1])
        exists = yield self.client.exists("/machines/%s" % machine_ids[0])
        self.assertTrue(exists)

        unit_ids = topology.get_service_units(service_id)
        self.assertEqual(unit_ids, ["unit-%010d" % 0])
        exists = yield self.client.exists("/units/%s" % unit_ids[0])
        self.assertTrue(exists)
Ejemplo n.º 25
0
    def test_deploy(self):
        """Create service, and service unit on machine from charm"""
        environment = self.config.get("firstenv")
        yield deploy.deploy(self.config, environment, self.unbundled_repo_path,
                            "local:sample", "myblog",
                            logging.getLogger("deploy"))
        topology = yield self.get_topology()

        service_id = topology.find_service_with_name("myblog")
        self.assertEqual(service_id, "service-%010d" % 0)
        exists = yield self.client.exists("/services/%s" % service_id)
        self.assertTrue(exists)

        machine_ids = topology.get_machines()
        self.assertEqual(
            machine_ids,
            ["machine-%010d" % 0, "machine-%010d" % 1])
        exists = yield self.client.exists("/machines/%s" % machine_ids[0])
        self.assertTrue(exists)

        unit_ids = topology.get_service_units(service_id)
        self.assertEqual(unit_ids, ["unit-%010d" % 0])
        exists = yield self.client.exists("/units/%s" % unit_ids[0])
        self.assertTrue(exists)