def test_add_security_service_association_error_status_active(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.share_network_update(self.fake_context, self.share_nw_dict["id"], {"status": constants.STATUS_ACTIVE}) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceAssociationError, db_api.share_network_add_security_service, self.fake_context, self.share_nw_dict["id"], security_dict1["id"], ) assoc_ref = ( sqlalchemy_api.model_query(self.fake_context, models.ShareNetworkSecurityServiceAssociation) .filter_by(security_service_id=security_dict1["id"]) .filter_by(share_network_id=self.share_nw_dict["id"]) .first() ) self.assertTrue(assoc_ref is None)
def test_add_security_service_association_error_status_active(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.share_network_update(self.fake_context, self.share_nw_dict['id'], {'status': constants.STATUS_ACTIVE}) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceAssociationError, db_api.share_network_add_security_service, self.fake_context, self.share_nw_dict['id'], security_dict1['id']) assoc_ref = sqlalchemy_api.model_query( self.fake_context, models.ShareNetworkSecurityServiceAssociation).\ filter_by(security_service_id=security_dict1['id']).\ filter_by(share_network_id=self.share_nw_dict['id']).first() self.assertTrue(assoc_ref is None)
def update(self, req, id, body): """Update specified share network.""" context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'update') if not body or RESOURCE_NAME not in body: raise exc.HTTPUnprocessableEntity() try: share_network = db_api.share_network_get(context, id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) update_values = body[RESOURCE_NAME] self._verify_no_mutually_exclusive_data(share_network, update_values) if share_network['share_servers']: for value in update_values: if value not in ['name', 'description']: msg = _("Cannot update share network %s. It is used by " "share servers. Only 'name' and 'description' " "fields are available for update")\ % share_network['id'] raise exc.HTTPForbidden(explanation=msg) try: share_network = db_api.share_network_update(context, id, update_values) except db_exception.DBError: msg = "Could not save supplied data due to database error" raise exc.HTTPBadRequest(explanation=msg) return self._view_builder.build_share_network(share_network)
def update(self, req, id, body): """Update specified share network.""" context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'update') if not body or RESOURCE_NAME not in body: raise exc.HTTPUnprocessableEntity() try: share_network = db_api.share_network_get(context, id) except exception.ShareNetworkNotFound as e: msg = "%s" % e raise exc.HTTPNotFound(explanation=msg) if share_network['share_servers']: msg = _("Cannot update share network %s." " It is used by share servers") % share_network['id'] raise exc.HTTPForbidden(explanation=msg) update_values = body[RESOURCE_NAME] try: share_network = db_api.share_network_update(context, id, update_values) except db_exception.DBError: msg = "Could not save supplied data due to database error" raise exc.HTTPBadRequest(explanation=msg) return self._view_builder.build_share_network(share_network)
def update(self, req, id, body): """Update specified share network.""" context = req.environ["manila.context"] policy.check_policy(context, RESOURCE_NAME, "update") if not body or RESOURCE_NAME not in body: raise exc.HTTPUnprocessableEntity() try: share_network = db_api.share_network_get(context, id) except exception.ShareNetworkNotFound as e: msg = "%s" % e raise exc.HTTPNotFound(explanation=msg) if share_network["status"] == constants.STATUS_ACTIVE: msg = "Network %s is in use" % id raise exc.HTTPBadRequest(explanation=msg) update_values = body[RESOURCE_NAME] try: share_network = db_api.share_network_update(context, id, update_values) except exception.DBError: msg = "Could not save supplied data due to database error" raise exc.HTTPBadRequest(explanation=msg) return self._view_builder.build_share_network(share_network)
def test_update(self): new_status = constants.STATUS_ERROR db_api.share_network_create(self.fake_context, self.share_nw_dict) result_update = db_api.share_network_update(self.fake_context, self.share_nw_dict["id"], {"status": new_status}) result_get = db_api.share_network_get(self.fake_context, self.share_nw_dict["id"]) self.assertEqual(result_update["status"], new_status) self._check_fields(expected=dict(result_update.iteritems()), actual=dict(result_get.iteritems()))
def test_update(self): new_name = 'fake_new_name' db_api.share_network_create(self.fake_context, self.share_nw_dict) result_update = db_api.share_network_update(self.fake_context, self.share_nw_dict['id'], {'name': new_name}) result_get = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(result_update['name'], new_name) self._check_fields(expected=dict(six.iteritems(result_update)), actual=dict(six.iteritems(result_get)))
def update(self, req, id, body): """Update specified share network.""" context = req.environ["manila.context"] policy.check_policy(context, RESOURCE_NAME, "update") if not body or RESOURCE_NAME not in body: raise exc.HTTPUnprocessableEntity() try: share_network = db_api.share_network_get(context, id) except exception.ShareNetworkNotFound as e: msg = "%s" % e raise exc.HTTPNotFound(explanation=msg) update_values = body[RESOURCE_NAME] if share_network["share_servers"]: for value in update_values: if value not in ["name", "description"]: msg = ( _( "Cannot update share network %s. It is used by " "share servers. Only 'name' and 'description' " "fields are available for update" ) % share_network["id"] ) raise exc.HTTPForbidden(explanation=msg) try: share_network = db_api.share_network_update(context, id, update_values) except db_exception.DBError: msg = "Could not save supplied data due to database error" raise exc.HTTPBadRequest(explanation=msg) return self._view_builder.build_share_network(share_network)
def update(self, req, id, body): """Update specified share network.""" context = req.environ['manila.context'] policy.check_policy(context, RESOURCE_NAME, 'update') if not body or RESOURCE_NAME not in body: raise exc.HTTPUnprocessableEntity() try: share_network = db_api.share_network_get(context, id) except exception.ShareNetworkNotFound as e: raise exc.HTTPNotFound(explanation=six.text_type(e)) update_values = body[RESOURCE_NAME] if 'nova_net_id' in update_values: msg = _("nova networking is not supported starting in Ocata.") raise exc.HTTPBadRequest(explanation=msg) if self._share_network_subnets_contain_share_servers(share_network): for value in update_values: if value not in ['name', 'description']: msg = (_("Cannot update share network %s. It is used by " "share servers. Only 'name' and 'description' " "fields are available for update") % share_network['id']) raise exc.HTTPForbidden(explanation=msg) try: if ('neutron_net_id' in update_values or 'neutron_subnet_id' in update_values): subnet = db_api.share_network_subnet_get_default_subnet( context, id) if not subnet: msg = _("The share network %(id)s does not have a " "'default' subnet that serves all availability " "zones, so subnet details " "('neutron_net_id', 'neutron_subnet_id') cannot " "be updated.") % { 'id': id } raise exc.HTTPBadRequest(explanation=msg) # NOTE(silvacarlose): If the default share network subnet have # the fields neutron_net_id and neutron_subnet_id set as None, # we need to make sure that in the update request the user is # passing both parameter since a share network subnet must # have both fields filled or empty. subnet_neutron_net_and_subnet_id_are_empty = ( subnet['neutron_net_id'] is None and subnet['neutron_subnet_id'] is None) update_values_without_neutron_net_or_subnet = ( update_values.get('neutron_net_id') is None or update_values.get('neutron_subnet_id') is None) if (subnet_neutron_net_and_subnet_id_are_empty and update_values_without_neutron_net_or_subnet): msg = _("To update the share network %(id)s you need to " "specify both 'neutron_net_id' and " "'neutron_subnet_id'.") % { 'id': id } raise webob.exc.HTTPBadRequest(explanation=msg) db_api.share_network_subnet_update(context, subnet['id'], update_values) share_network = db_api.share_network_update( context, id, update_values) except db_exception.DBError: msg = "Could not save supplied data due to database error" raise exc.HTTPBadRequest(explanation=msg) return self._view_builder.build_share_network(req, share_network)
def _update(self, *args, **kwargs): db_api.share_network_update(*args, **kwargs)