Beispiel #1
0
 def execute(self, server_info, image_info, flavor_info, keypair_info,
             user_info, tenant_info, server_nics, server_dm):
     restrict_cloud = self.cloud.restrict(
         username=user_info["name"],
         tenant_name=tenant_info["name"],
         password="default")
     if keypair_info is not None:
         key_name = keypair_info["name"]
     else:
         key_name = None
     server = restrict_cloud.nova.servers.create(
         server_info["name"], image_info["id"], flavor_info["id"],
         block_device_mapping=dict(server_dm),
         nics=server_nics,
         key_name=key_name)
     server = utils.wait_for(server, self.cloud.nova.servers.get,
                             value="ACTIVE")
     spawn_server_info = server.to_dict()
     for volume_id in dict(server_dm).values():
         volume = self.cloud.cinder.volumes.get(volume_id)
         volume = utils.wait_for(volume.id,
                                 self.cloud.cinder.volumes.get,
                                 value="in-use")
         self.attach_event(volume.id,
                           server.id)
     self.spawn_event(spawn_server_info)
     return spawn_server_info
Beispiel #2
0
 def test_wait_for_value_and_timeout(self):
     with self.assertRaises(excs.TimeoutException):
         utils.wait_for(
             self.resource,
             self.update_resource,
             attribute_getter=self.attribute_getter,
             timeout=self.timeout,
             check_interval=self.check_interval
         )
Beispiel #3
0
 def execute(self, volumes, **requires):
     for volume_info in volumes:
         try:
             volume = self.cloud.cinder.volumes.get(volume_info["id"])
         except exceptions.cinder_excs.NotFound:
             LOG.info("Volume ID non-existent: %s", volume_info)
             pass
         else:
             utils.wait_for(volume.id,
                            self.cloud.cinder.volumes.get,
                            value="available")
             self.do_delete(volume._info)
Beispiel #4
0
 def revert(self, server_info, result, flow_failures):
     self.cloud.nova.servers.resume(server_info["id"])
     server = utils.wait_for(server_info["id"], self.cloud.nova.servers.get,
                             value="ACTIVE")
     resume_server_info = server.to_dict()
     self.resume_event(resume_server_info)
     return resume_server_info
Beispiel #5
0
 def execute(self, server_info):
     self.cloud.nova.servers.suspend(server_info["id"])
     server = utils.wait_for(server_info["id"], self.cloud.nova.servers.get,
                             value="SUSPENDED")
     suspend_server_info = server.to_dict()
     self.suspend_event(suspend_server_info)
     return suspend_server_info
Beispiel #6
0
 def execute(self, volume_info, image_info,
             user_info, tenant_info, timeout):
     image_id = image_info["id"]
     if user_info:
         restrict_cloud = self.cloud.restrict(
             username=user_info["name"],
             tenant_name=tenant_info["name"],
             password="default")
     else:
         restrict_cloud = self.cloud.restrict(
             tenant_name=tenant_info["name"])
     try:
         volume = restrict_cloud.cinder.volumes.create(
             volume_info["size"],
             display_name=volume_info["display_name"],
             display_description=volume_info["display_description"],
             imageRef=image_id)
     except Exception as exc:
         LOG.exception("Cannot create: %s", volume_info)
         raise exc
     else:
         volume = utils.wait_for(volume.id,
                                 self.cloud.cinder.volumes.get,
                                 value="available",
                                 timeout=timeout,
                                 check_interval=3)
         self.create_volume_event(volume._info)
     return volume._info
Beispiel #7
0
 def execute(self, volume, target_host):
     LOG.info("Evacuating volume %s to host %s...", volume.id, target_host)
     self.cloud.cinder.volumes.migrate_volume(volume, target_host, False)
     volume = utils.wait_for(volume.id, self.cloud.cinder.volumes.get,
                             get_volume_host, target_host)
     events.emit("update", event_from(self.cloud, volume),
                 namespace="/events")
     LOG.info("Evacuated volume %s to host %s", volume.id, target_host)
Beispiel #8
0
 def execute(self, node_info, **requires):
     condition_check = lambda x: x is not None
     node_macs = extract_macs(node_info)
     unassigned_node_info = utils.wait_for(node_macs,
                                           self.retrieve_unassigned,
                                           attribute_getter=condition_check,
                                           value=True,
                                           timeout=360)
     return unassigned_node_info
Beispiel #9
0
 def attach(self):
     if self.data.get("server"):
         device = None
         self.env.cloud.nova.volumes.create_server_volume(
             self.data["server"]["id"], self.data["id"], device)
         volume = utils.wait_for(self.data["id"],
                                 self.env.cloud.cinder.volumes.get,
                                 value="in-use")
         self.data = volume._info
Beispiel #10
0
 def detach(self):
     for attachment in self.data["attachments"]:
         server_id = attachment["server_id"]
         self.env.cloud.nova.volumes.delete_server_volume(server_id,
                                                          self.data["id"])
     if self.data["attachments"]:
         volume = utils.wait_for(self.data["id"],
                                 self.env.cloud.cinder.volumes.get,
                                 value="available")
         self.data = volume._info
Beispiel #11
0
 def test_wait_for_success_on_first_pass(self):
     result = utils.wait_for(
         self.resource,
         self.update_resource,
         attribute_getter=self.attribute_getter,
         value=self.value,
         timeout=self.timeout,
         check_interval=self.check_interval
     )
     self.update_resource.assert_called_once_with(self.resource)
     self.attribute_getter.assert_called_once_with(self.upd_resource)
     self.assertEqual(result, self.upd_resource)
Beispiel #12
0
 def test_wait_for_stop_exception(self):
     self.update_resource.side_effect = Exception("This should be caught")
     result = utils.wait_for(
         self.resource,
         self.update_resource,
         attribute_getter=self.attribute_getter,
         value=self.value,
         timeout=self.timeout,
         check_interval=self.check_interval,
         stop_excs=Exception
     )
     self.assertEqual(result, None)
Beispiel #13
0
 def test_wait_for_expected_exception(self):
     self.update_resource.side_effect = (Exception, self.upd_resource)
     result = utils.wait_for(
         self.resource,
         self.update_resource,
         attribute_getter=self.attribute_getter,
         value=self.value,
         timeout=self.timeout,
         check_interval=self.check_interval,
         expect_excs=Exception
     )
     self.assertEqual(result, self.upd_resource)
Beispiel #14
0
def setup_server(cloud, server_dict):
    image = list(cloud.glance.images.list(
        filters={
            "name": server_dict["image"]["name"]
        }))[0]
    flavor = cloud.nova.flavors.find(name=server_dict["flavor"]["name"])
    server_params = (server_dict["name"],
                     image.id,
                     flavor.id)
    server = cloud.nova.servers.create(*server_params)
    server = utils.wait_for(server.id, cloud.nova.servers.get,
                            value="ACTIVE")
    return server
Beispiel #15
0
 def do_delete(self, volume_info):
     volume = self.cloud.cinder.volumes.get(volume_info["id"])
     try:
         self.cloud.cinder.volumes.delete(volume.id)
     except exceptions.cinder_excs.BadRequest as exc:
         LOG.exception("Cannot delete: %s", str(volume._info))
         raise exc
     else:
         volume = utils.wait_for(volume.id, self.cloud.cinder.volumes.get,
                                 stop_excs=(
                                     exceptions.cinder_excs.NotFound,))
         LOG.info("Deleted: %s", str(volume_info))
         self.delete_volume_event(volume_info)
Beispiel #16
0
 def execute(self, volume_info, timeout, **requires):
     try:
         volume = self.cloud.cinder.volumes.create(
             volume_info["size"], source_volid=volume_info["id"])
     except exceptions.cinder_excs.NotFound as exc:
         LOG.exception("Source volume not found: %s", volume_info)
         raise exc
     else:
         volume = utils.wait_for(volume.id, self.cloud.cinder.volumes.get,
                                 value='available', timeout=timeout,
                                 check_interval=3)
         self.create_volume_event(volume._info)
     return volume._info
Beispiel #17
0
 def execute(self, server_info, **requires):
     server_id = server_info["id"]
     self.evacuation_event(server_info)
     # NOTE(akscram): The destination host will be chosen by the
     #                scheduler.
     self.cloud.nova.servers.live_migrate(server_id, None,
                                          self.block_migration,
                                          self.disk_over_commit)
     server = self.cloud.nova.servers.get(server_id)
     self.evacuation_event(server.to_dict())
     server = utils.wait_for(server.id, self.cloud.nova.servers.get)
     migrated_server_info = server.to_dict()
     self.evacuation_event(migrated_server_info)
     return migrated_server_info
Beispiel #18
0
 def create(self):
     cloud = self.env.cloud.restrict(
         tenant_name=self.tenant["name"],
     )
     volume = cloud.cinder.volumes.create(
         self.data["size"],
         display_name=self.data["display_name"],
     )
     volume = utils.wait_for(volume.id, self.env.cloud.cinder.volumes.get,
                             value="available")
     self.data = dict(volume._info,
                      **make_kwargs(
                          server=self.data.get("server"),
                      ))
Beispiel #19
0
 def execute(self, attachment):
     self.cloud.nova.volumes.create_server_volume(
         attachment["server_id"],
         attachment["volume_id"],
         attachment["device"],
     )
     volume = utils.wait_for(
         attachment["volume_id"],
         self.cloud.cinder.volumes.get,
         value="in-use",
     )
     events.emit("update", event_from(self.cloud, volume),
                 namespace="/events")
     LOG.info("Reattached volume %(volume_id)s from server %(server_id)s",
              attachment)
Beispiel #20
0
 def execute(self, attachment):
     LOG.info("Detaching volume %(volume_id)s from server %(server_id)s...",
              attachment)
     self.cloud.nova.volumes.delete_server_volume(
         attachment["server_id"],
         attachment["id"],
     )
     volume = utils.wait_for(
         attachment["volume_id"],
         self.cloud.cinder.volumes.get,
         value="available",
     )
     events.emit("update", event_from(self.cloud, volume),
                 namespace="/events")
     LOG.info("Detached volume %(volume_id)s from server %(server_id)s",
              attachment)
Beispiel #21
0
 def execute(self, server_info):
     server_id = server_info["id"]
     snapshot_name = "{}-snapshot-{}".format(server_info["name"], server_id)
     try:
         snapshot_id = self.cloud.nova.servers.create_image(
             server_id, snapshot_name)
     except Exception:
         LOG.exception("Snapshot failed for server: %s", server_id)
         raise
     else:
         snapshot = self.cloud.glance.images.get(snapshot_id)
         snapshot = utils.wait_for(snapshot.id,
                                   self.cloud.glance.images.get,
                                   value="active")
         LOG.info("Created: %s", snapshot)
         self.created_event(snapshot)
         return snapshot.id
Beispiel #22
0
 def execute(self, volume_info, image_info):
     image_id = image_info["id"]
     try:
         volume = self.cloud.cinder.volumes.create(
             volume_info["size"],
             display_name=volume_info["display_name"],
             display_description=volume_info["display_description"],
             volume_type=volume_info["volume_type"],
             imageRef=image_id)
     except Exception as exc:
         LOG.exception("Cannot create: %s", volume_info)
         raise exc
     else:
         volume = utils.wait_for(volume.id,
                                 self.cloud.cinder.volumes.get,
                                 value="available",
                                 timeout=120,
                                 check_interval=10)
         self.create_volume_event(volume._info)
     return volume._info
Beispiel #23
0
    def execute(self, volume_info, timeout):
        volume_id = volume_info["id"]

        try:

            # TODO (sryabin) check the volume has been detached
            snapshot = self.cloud.cinder.volume_snapshots.create(volume_id)

        except Exception as e:
            LOG.exception("Can't create snapshot from volume: %s",
                          str(volume_info))

        snapshot = utils.wait_for(
            snapshot.id,
            self.cloud.cinder.volume_snapshots.get,
            value='available',
            timeout=timeout,
            error_value='error')

        return snapshot._info
Beispiel #24
0
 def execute(self, volume_info):
     volume_id = volume_info["id"]
     try:
         resp, upload_info = self.cloud.cinder.volumes.upload_to_image(
             volume_id,
             False,
             "volume-{}-image".format(volume_id),
             'bare',
             'raw')
     except Exception as exc:
         LOG.exception("Upload failed: %s", exc.message)
         raise exc
     image_id = upload_info["os-volume_upload_image"]["image_id"]
     try:
         image = self.cloud.glance.images.get(image_id)
     except exceptions.glance_excs.NotFound:
         LOG.exception("Image not found: %s", image_id)
         raise exceptions.NotFound()
     image = utils.wait_for(image.id,
                            self.cloud.glance.images.get,
                            value="active")
     self.upload_to_glance_event(dict(image))
     return image.id
Beispiel #25
0
    def create(self):
        cloud = self.env.cloud.restrict(
            username=self.user["name"],
            password="default",
            tenant_name=self.tenant["name"],
        )
        server = cloud.nova.servers.create(
            self.data["name"],
            self.image["id"],
            self.flavor["id"],
            nics=[nic["nic"] for nic in self.nics],
            key_name=self.keypair["name"],
        )

        def _do_get(id_):
            last_event_data = None
            yield
            while True:
                res = self.env.cloud.nova.servers.get(id_)
                self.data = res.to_dict()
                event_data = self.event_data()
                if last_event_data is None:
                    self.post_event("create")
                    last_event_data = event_data
                elif last_event_data != event_data:
                    self.post_event("update")
                    last_event_data = event_data
                yield res

        do_get = _do_get(server.id)
        next(do_get)
        server = utils.wait_for(server.id, do_get.send, value="ACTIVE")
        server = server.to_dict()
        for floating_ip in self.floating_ips:
            floating_ip["server"] = server
        for volume in self.volumes:
            volume["server"] = server
Beispiel #26
0
 def execute(self, hostname, **requires):
     hypervisors = utils.wait_for(hostname,
                                  self.get_hypervisors,
                                  attribute_getter=bool,
                                  value=True)
     return hypervisors
Beispiel #27
0
def cleanup(events, cloud, target):
    def is_prefixed(string):
        return string.startswith(TEST_RESOURCE_PREFIX)
    search_opts = {"all_tenants": 1}
    for server in cloud.nova.servers.list(search_opts=search_opts):
        if not is_prefixed(server.name):
            continue
        try:
            server_floating_ips = cloud.nova.floating_ips_bulk.findall(
                instance_uuid=server.id)
        except nova_excs.NotFound:
            LOG.info("No floating ips found for server: %s",
                     server._info)
        else:
            for floating_ip in server_floating_ips:
                cloud.nova.servers.remove_floating_ip(server,
                                                      floating_ip.address)
                LOG.info("Removed floating ip address: %s",
                         floating_ip._info)
        cloud.nova.servers.delete(server)
        utils.wait_for(server, cloud.nova.servers.get,
                       stop_excs=(nova_excs.NotFound,))
        LOG.info("Deleted server: %s", server._info)
        hostname = getattr(server, "OS-EXT-SRV-ATTR:hypervisor_hostname")
        events.emit("server terminate", {
            "cloud": target,
            "id": server.id,
            "host_name": hostname
        }, namespace="/events")

    for flavor in cloud.nova.flavors.list():
        if is_prefixed(flavor.name):
            cloud.nova.flavors.delete(flavor)
            LOG.info("Deleted flavor: %s", flavor._info)
            events.emit("flavor delete", {
                "cloud": target,
                "id": flavor.id,
            }, namespace="/events")

    if (cloud.cinder):
        for volume in cloud.cinder.volumes.list(
                search_opts={'all_tenants': 1}):
            vol_name = volume._info['display_name']
            vol_id = volume._info['id']
            if vol_name and is_prefixed(vol_name):
                cloud.cinder.volumes.delete(vol_id)

                LOG.info("Delete volume: %s", str(volume._info))
                events.emit("volume delete", {
                    "cloud": target,
                    "id": vol_id
                }, namespace="/events")

    for image in cloud.glance.images.list():
        if not is_prefixed(image.name):
            continue
        cloud.glance.images.delete(image.id)
        LOG.info("Deleted image: %s", dict(image))
        events.emit("image delete", {
            "cloud": target,
            "id": image.id
        }, namespace="/events")

    for secgroup in cloud.nova.security_groups.list():
        if not is_prefixed(secgroup.name):
            continue
        if secgroup.name in RO_SECURITY_GROUPS:
            for rule in secgroup.rules:
                cloud.nova.security_group_rules.delete(rule['id'])
                LOG.info("Deleted rule from default secgroup: %s", rule)
        else:
            cloud.nova.security_groups.delete(secgroup.id)
            LOG.info("Deleted secgroup: %s", secgroup._info)
        events.emit("secgroup delete", {
            "cloud": target,
            "id": secgroup.id
        }, namespace="/events")

    for floating_ip in cloud.nova.floating_ips_bulk.list():
        cloud.nova.floating_ips_bulk.delete(floating_ip.address)
        LOG.info("Deleted floating ip: %s", floating_ip._info)
        events.emit("floating_ip delete", {
            "cloud": target,
            "id": floating_ip.address
        }, namespace="/events")

    if (cloud.neutron):
        for port in cloud.neutron.list_ports()['ports']:
            LOG.info("Deleted network: %s", port['id'])
            cloud.neutron.delete_port(port['id'])

        for subnet in cloud.neutron.list_subnets()['subnets']:
            LOG.info("Deleted subnet: %s", subnet['name'])
            cloud.neutron.delete_subnet(subnet['id'])

        for network in cloud.neutron.list_networks()['networks']:
            LOG.info("Delete network: %s", network['name'])
            cloud.neutron.delete_network(network['id'])

            LOG.info("Deleted network: %s", network._info)
            events.emit("network delete", {
                "cloud": target,
                "id": network['id']
            }, namespace="/events")

    for network in cloud.nova.networks.list():
        if not is_prefixed(network.label):
            continue
        cloud.nova.networks.disassociate(network)
        cloud.nova.networks.delete(network)
        LOG.info("Deleted network: %s", network._info)
        events.emit("network delete", {
            "cloud": target,
            "id": network.id
        }, namespace="/events")

    for user in cloud.keystone.users.list():
        if is_prefixed(user.name):
            cloud.keystone.users.delete(user)
            LOG.info("Deleted user: %s", user._info)
            events.emit("user delete", {
                "cloud": target,
                "id": user.id
            }, namespace="/events")

    for role in cloud.keystone.roles.list():
        if is_prefixed(role.name):
            cloud.keystone.roles.delete(role)
            LOG.info("Deleted role: %s", role._info)
            events.emit("role delete", {
                "cloud": target,
                "id": role.id
            }, namespace="/events")

    for tenant in cloud.keystone.tenants.list():
        if is_prefixed(tenant.name):
            cloud.keystone.tenants.delete(tenant)
            LOG.info("Deleted role: %s", tenant._info)
            events.emit("tenant delete", {
                "cloud": target,
                "id": tenant.id,
            }, namespace="/events")

    services = cloud.nova.services.list(binary="nova-compute")
    for service in services:
        if service.status == "disabled":
            cloud.nova.services.enable(service.host, "nova-compute")
            LOG.info("Enabled the nova-compute service on %s", service.host)
            events.emit("", {
                "cloud": target,
                "name": service.host,
            }, namespace="/events")
Beispiel #28
0
 def delete(self):
     self.env.cloud.nova.servers.delete(self.data["id"])
     utils.wait_for(self.data["id"], self.env.cloud.nova.servers.get,
                    stop_excs=(nova_excs.NotFound,))
     self.post_event("delete")