Beispiel #1
0
 def test_create_cluster_with_multi_keypair_same_name(self):
     bdict = apiutils.cluster_post_data()
     self.mock_valid_os_res.side_effect = exception.Conflict('keypair2')
     response = self.post_json('/clusters', bdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(self.mock_valid_os_res.called)
     self.assertEqual(409, response.status_int)
Beispiel #2
0
def get_openstack_resource(manager, resource_ident, resource_type):
    """Get the openstack resource from the uuid or logical name.

    :param manager: the resource manager class.
    :param resource_ident: the UUID or logical name of the resource.
    :param resource_type: the type of the resource

    :returns: The openstack resource.
    :raises: ResourceNotFound if the openstack resource is not exist.
             Conflict if multi openstack resources have same name.
    """
    if uuidutils.is_uuid_like(resource_ident):
        resource_data = manager.get(resource_ident)
    else:
        filters = {'name': resource_ident}
        matches = list(manager.list(filters=filters))
        if len(matches) == 0:
            raise exception.ResourceNotFound(name=resource_type,
                                             id=resource_ident)
        if len(matches) > 1:
            msg = _LE("Multiple %(resource_type)s exist with same name "
                      "%(resource_ident)s. Please use the resource id "
                      "instead.") % {'resource_type': resource_type,
                                     'resource_ident': resource_ident}
            raise exception.Conflict(msg)
        resource_data = matches[0]
    return resource_data
Beispiel #3
0
 def test_create_bay_with_multi_images_same_name(self):
     bdict = apiutils.bay_post_data()
     self.mock_valid_os_res.side_effect = exception.Conflict('test-img')
     response = self.post_json('/bays', bdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(self.mock_valid_os_res.called)
     self.assertEqual(409, response.status_int)
Beispiel #4
0
 def test_create_baymodel_with_multi_image_name(self, mock_keypair_exists,
                                                mock_image_data):
     mock_keypair_exists.return_value = None
     mock_image_data.side_effect = exception.Conflict('Multiple images')
     bdict = apiutils.baymodel_post_data()
     del bdict['uuid']
     response = self.post_json('/baymodels', bdict, expect_errors=True)
     self.assertEqual(409, response.status_int)
Beispiel #5
0
 def get_pod_by_name(self, pod_name):
     query = model_query(models.Pod).filter_by(name=pod_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple pods exist with same name.'
                                  ' Please use the pod uuid instead.')
     except NoResultFound:
         raise exception.PodNotFound(pod=pod_name)
Beispiel #6
0
 def get_rc_by_name(self, rc_name):
     query = model_query(
         models.ReplicationController).filter_by(name=rc_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple rcs exist with same name.'
                                  ' Please use the rc uuid instead.')
     except NoResultFound:
         raise exception.ReplicationControllerNotFound(rc=rc_name)
Beispiel #7
0
 def get_cluster_by_name(self, context, cluster_name):
     query = model_query(models.Cluster)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(name=cluster_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple clusters exist with same name.'
                                  ' Please use the cluster uuid instead.')
     except NoResultFound:
         raise exception.ClusterNotFound(cluster=cluster_name)
Beispiel #8
0
 def get_service_by_name(self, context, service_name):
     query = model_query(models.Service)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(name=service_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple services exist with same name.'
                                  ' Please use the service uuid instead.')
     except NoResultFound:
         raise exception.ServiceNotFound(service=service_name)
Beispiel #9
0
 def get_baymodel_by_name(self, context, baymodel_name):
     query = model_query(models.BayModel)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(name=baymodel_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple baymodels exist with same name.'
                                  ' Please use the baymodel uuid instead.')
     except NoResultFound:
         raise exception.BayModelNotFound(baymodel=baymodel_name)
Beispiel #10
0
 def get_federation_by_name(self, context, federation_name):
     query = model_query(models.Federation)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(name=federation_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple federations exist with same '
                                  'name. Please use the federation uuid '
                                  'instead.')
     except NoResultFound:
         raise exception.FederationNotFound(federation=federation_name)
Beispiel #11
0
 def get_x509keypair_by_name(self, context, x509keypair_name):
     query = model_query(models.X509KeyPair)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(name=x509keypair_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple x509keypairs exist with '
                                  'same name. Please use the x509keypair '
                                  'uuid instead.')
     except NoResultFound:
         raise exception.X509KeyPairNotFound(x509keypair=x509keypair_name)
Beispiel #12
0
 def get_nodegroup_by_name(self, context, cluster_id, nodegroup_name):
     query = model_query(models.NodeGroup)
     if not context.is_admin:
         query = query.filter_by(project_id=context.project_id)
     query = query.filter_by(cluster_id=cluster_id)
     query = query.filter_by(name=nodegroup_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple nodegroups exist with same '
                                  'name. Please use the nodegroup uuid '
                                  'instead.')
     except NoResultFound:
         raise exception.NodeGroupNotFound(nodegroup=nodegroup_name)
Beispiel #13
0
 def get_baymodel_by_name(self, context, baymodel_name):
     query = model_query(models.BayModel)
     query = self._add_tenant_filters(context, query)
     public_q = model_query(models.BayModel).filter_by(public=True)
     query = query.union(public_q)
     query = query.filter_by(name=baymodel_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple baymodels exist with same name.'
                                  ' Please use the baymodel uuid instead.')
     except NoResultFound:
         raise exception.ClusterTemplateNotFound(
             clustertemplate=baymodel_name)
Beispiel #14
0
 def get_cluster_template_by_name(self, context, cluster_template_name):
     query = model_query(models.ClusterTemplate)
     query = self._add_tenant_filters(context, query)
     public_q = model_query(models.ClusterTemplate).filter_by(public=True)
     query = query.union(public_q)
     query = query.filter_by(name=cluster_template_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple ClusterTemplates exist with'
                                  ' same name. Please use the '
                                  'ClusterTemplate uuid instead.')
     except NoResultFound:
         raise exception.ClusterTemplateNotFound(
             clustertemplate=cluster_template_name)
Beispiel #15
0
def get_network_id(context, network_name):
    nets = []
    n_client = clients.OpenStackClients(context).neutron()
    ext_filter = {'router:external': True}

    networks = n_client.list_networks(**ext_filter)
    for net in networks.get('networks'):
        if net.get('name') == network_name:
            nets.append(net)

    if len(nets) == 0:
        raise exception.ExternalNetworkNotFound(network=network_name)

    if len(nets) > 1:
        raise exception.Conflict(
            "Multiple networks exist with same name '%s'. Please use the "
            "network ID instead." % network_name)

    return nets[0]["id"]
Beispiel #16
0
def get_subnet(context, subnet, source, target):
    nets = []
    n_client = clients.OpenStackClients(context).neutron()
    filters = {source: subnet}
    subnets = n_client.list_subnets(**filters).get('subnets', [])

    for net in subnets:
        if net.get(source) == subnet:
            nets.append(net)

    if len(nets) == 0:
        raise exception.FixedSubnetNotFound(subnet=subnet)

    if len(nets) > 1:
        raise exception.Conflict(
            "Multiple subnets exist with same name '%s'. Please use the "
            "subnet ID instead." % subnet)

    return nets[0][target]
Beispiel #17
0
def validate_external_network(cli, external_network):
    """Validate external network"""

    count = 0
    ext_filter = {'router:external': True}
    networks = cli.neutron().list_networks(**ext_filter)
    for net in networks.get('networks'):
        if (net.get('name') == external_network
                or net.get('id') == external_network):
            count = count + 1

    if count == 0:
        # Unable to find the external network.
        # Or the network is private.
        raise exception.ExternalNetworkNotFound(network=external_network)

    if count > 1:
        msg = _("Multiple external networks exist with same name '%s'. "
                "Please use the external network ID instead.")
        raise exception.Conflict(msg % external_network)
Beispiel #18
0
def get_network(context, network, source, target, external):
    nets = []
    n_client = clients.OpenStackClients(context).neutron()
    ext_filter = {'router:external': external}

    networks = n_client.list_networks(**ext_filter)
    for net in networks.get('networks'):
        if net.get(source) == network:
            nets.append(net)

    if len(nets) == 0:
        if external:
            raise exception.ExternalNetworkNotFound(network=network)
        else:
            raise exception.FixedNetworkNotFound(network=network)

    if len(nets) > 1:
        raise exception.Conflict(
            "Multiple networks exist with same name '%s'. Please use the "
            "network ID instead." % network)

    return nets[0][target]
Beispiel #19
0
 def test_Conflict(self):
     self.assertRaises(exception.Conflict,
                       lambda: self.raise_(exception.Conflict()))