예제 #1
0
 def test_boot_servers_with_affinity_overquota(self):
     # Tests that we check server group member quotas and cleanup created
     # resources when we fail with OverQuota.
     self.flags(server_group_members=1, group='quota')
     # make sure we start with 0 servers
     servers = self.api.get_servers(detail=False)
     self.assertEqual(0, len(servers))
     created_group = self.api.post_server_groups(self.affinity)
     ex = self.assertRaises(client.OpenStackApiException,
                            self._boot_servers_to_group,
                            created_group)
     self.assertEqual(403, ex.response.status_code)
     # _boot_servers_to_group creates 2 instances in the group in order, not
     # multiple servers in a single request. Since our quota is 1, the first
     # server create would pass, the second should fail, and we should be
     # left with 1 server and it's 1 block device mapping.
     servers = self.api.get_servers(detail=False)
     self.assertEqual(1, len(servers))
     ctxt = context.get_admin_context()
     servers = db.instance_get_all(ctxt)
     self.assertEqual(1, len(servers))
     ctxt_mgr = db_api.get_context_manager(ctxt)
     with ctxt_mgr.reader.using(ctxt):
         bdms = db_api._block_device_mapping_get_query(ctxt).all()
     self.assertEqual(1, len(bdms))
     self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid'])
예제 #2
0
 def test_boot_servers_with_affinity_overquota(self):
     # Tests that we check server group member quotas and cleanup created
     # resources when we fail with OverQuota.
     self.flags(server_group_members=1, group='quota')
     # make sure we start with 0 servers
     servers = self.api.get_servers(detail=False)
     self.assertEqual(0, len(servers))
     created_group = self.api.post_server_groups(self.affinity)
     ex = self.assertRaises(client.OpenStackApiException,
                            self._boot_servers_to_group,
                            created_group)
     self.assertEqual(403, ex.response.status_code)
     # _boot_servers_to_group creates 2 instances in the group in order, not
     # multiple servers in a single request. Since our quota is 1, the first
     # server create would pass, the second should fail, and we should be
     # left with 1 server and it's 1 block device mapping.
     servers = self.api.get_servers(detail=False)
     self.assertEqual(1, len(servers))
     ctxt = context.get_admin_context()
     servers = db.instance_get_all(ctxt)
     self.assertEqual(1, len(servers))
     ctxt_mgr = db_api.get_context_manager(ctxt)
     with ctxt_mgr.reader.using(ctxt):
         bdms = db_api._block_device_mapping_get_query(ctxt).all()
     self.assertEqual(1, len(bdms))
     self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid'])
예제 #3
0
def _neutron_unused_port_cleanup(context):
    """
    This task periodically runs to check if there are any 'stale' neutron
    ports that need cleanup or not and eventually cleans it up. 'stale'
    ports are those which are not in use by any of the instance and hence
    should be freed up for deploys if they exit

    :param context: The context object.
    """
    LOG.debug('pvc_nova.compute.manager.PowerVCComputeManager '
              '_neutron_unused_port_cleanup: Cleaning up unused neutron '
              'ports...')
    #Get all the running instances from the DB which aren't deleted.
    ports_ids_to_delete = []
    try:
        # Expensive!
        db_instances = nova_db.instance_get_all(context)

        # Get all the neutron ports.  Expensive!
        network_data = neutronv2.get_client(context).list_ports()
        ports = network_data.get('ports', [])

        # We run through the list of ports and see if they have a device_id
        # If the device_id exists, we see if they are in use with an
        # instance or not, if No, then we delete them.
        for port in ports:
            found_server = False
            for instance in db_instances:
                if port.get('device_id', None) is not None and\
                        port['device_id'] == instance['uuid']:
                    found_server = True
                    break

            # Only delete ports that are owned by Compute.  Do NOT
            # delete ports owned by say SCE.
            dev_owner = port.get('device_owner', None)
            owned_by_compute = False
            if dev_owner is not None and dev_owner == 'compute:None':
                owned_by_compute = True

            if not found_server and owned_by_compute:
                ports_ids_to_delete.append(port['id'])
                LOG.info(_('Deleting neutron port with id %(id)s and data '
                           '%(data)s') % {'id': port['id'], 'data': str(port)})
    except Exception as exc:
        LOG.exception(exc)

    # Now iterate the legit candidates for deletion and delete them.
    for port_id in ports_ids_to_delete:
        try:
            neutronv2.get_client(context).delete_port(port_id)
            LOG.warning(_('Cleaning up the unused neutron port with id '
                          '%(port)s') % {'port': port_id})
        except Exception as exc:
            LOG.exception(exc)
    LOG.debug('Exiting neutron port clean up')
예제 #4
0
    def test_instance_list_minimal_cells(self):
        """Get a list of instances with a subset of cell mappings."""
        last_cell = self.cells[-1]
        with context.target_cell(self.context, last_cell) as cctxt:
            last_cell_instances = db.instance_get_all(cctxt)
            last_cell_uuids = [inst['uuid'] for inst in last_cell_instances]

        instances = list(
            instance_list.get_instances_sorted(self.context, {},
                                               None, None, [],
                                               ['uuid'], ['asc'],
                                               cell_mappings=self.cells[:-1]))
        found_uuids = [inst['hostname'] for inst in instances]
        had_uuids = [inst['hostname'] for inst in self.instances
                     if inst['uuid'] not in last_cell_uuids]
        self.assertEqual(sorted(had_uuids), sorted(found_uuids))
예제 #5
0
    def test_instance_list_minimal_cells(self):
        """Get a list of instances with a subset of cell mappings."""
        last_cell = self.cells[-1]
        with context.target_cell(self.context, last_cell) as cctxt:
            last_cell_instances = db.instance_get_all(cctxt)
            last_cell_uuids = [inst['uuid'] for inst in last_cell_instances]

        instances = list(
            instance_list.get_instances_sorted(self.context, {},
                                               None, None, [],
                                               ['uuid'], ['asc'],
                                               cell_mappings=self.cells[:-1]))
        found_uuids = [inst['hostname'] for inst in instances]
        had_uuids = [inst['hostname'] for inst in self.instances
                     if inst['uuid'] not in last_cell_uuids]
        self.assertEqual(sorted(had_uuids), sorted(found_uuids))