Exemple #1
0
    def remove_machine_state(self, machine_id):
        """Remove machine state identified by `machine_id` if present.

        Returns True if machine state was actually removed.
        """
        internal_id = "machine-%010d" % machine_id
        must_delete = [False]

        def remove_machine(topology):
            # Removing a non-existing machine again won't fail, since
            # the end intention is preserved.  This makes dealing
            # with concurrency easier.
            if topology.has_machine(internal_id):
                if topology.machine_has_units(internal_id):
                    raise MachineStateInUse(machine_id)
                topology.remove_machine(internal_id)
                must_delete[0] = True
            else:
                must_delete[0] = False
        yield self._retry_topology_change(remove_machine)
        if must_delete[0]:
            # If the process is interrupted here, this node will stay
            # around, but it's not a big deal since it's not being
            # referenced by the topology anymore.
            yield remove_tree(self._client, "/machines/%s" % (internal_id,))
        returnValue(must_delete[0])
Exemple #2
0
    def remove_machine_state(self, machine_id):
        """Remove machine state identified by `machine_id` if present.

        Returns True if machine state was actually removed.
        """
        internal_id = "machine-%010d" % machine_id
        must_delete = [False]

        def remove_machine(topology):
            # Removing a non-existing machine again won't fail, since
            # the end intention is preserved.  This makes dealing
            # with concurrency easier.
            if topology.has_machine(internal_id):
                if topology.machine_has_units(internal_id):
                    raise MachineStateInUse(machine_id)
                topology.remove_machine(internal_id)
                must_delete[0] = True
            else:
                must_delete[0] = False

        yield self._retry_topology_change(remove_machine)
        if must_delete[0]:
            # If the process is interrupted here, this node will stay
            # around, but it's not a big deal since it's not being
            # referenced by the topology anymore.
            yield remove_tree(self._client, "/machines/%s" % (internal_id, ))
        returnValue(must_delete[0])
Exemple #3
0
    def test_remove_tree(self):
        yield self.client.create("/zoo")
        yield self.client.create("/zoo/mammals")
        yield self.client.create("/zoo/mammals/elephant")
        yield self.client.create("/zoo/reptiles")
        yield self.client.create("/zoo/reptiles/snake")

        yield remove_tree(self.client, "/zoo")

        children = yield self.client.get_children("/")
        self.assertNotIn("zoo", children)
Exemple #4
0
    def test_remove_tree(self):
        yield self.client.create("/zoo")
        yield self.client.create("/zoo/mammals")
        yield self.client.create("/zoo/mammals/elephant")
        yield self.client.create("/zoo/reptiles")
        yield self.client.create("/zoo/reptiles/snake")

        yield remove_tree(self.client, "/zoo")

        children = yield self.client.get_children("/")
        self.assertNotIn("zoo", children)
Exemple #5
0
 def tearDown(self):
     exists = yield self.client.exists(self.path)
     if exists:
         yield remove_tree(self.client, self.path)
Exemple #6
0
 def tearDown(self):
     exists = yield self.client.exists(self.path)
     if exists:
         yield remove_tree(self.client, self.path)