예제 #1
0
    def test_remove_security_service(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.security_service_create(self.fake_context, security_dict1)
        db_api.share_network_add_security_service(self.fake_context,
                                                  self.share_nw_dict['id'],
                                                  security_dict1['id'])

        db_api.share_network_remove_security_service(self.fake_context,
                                                     self.share_nw_dict['id'],
                                                     security_dict1['id'])

        result = 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(result is None)

        share_nw_ref = db_api.share_network_get(self.fake_context,
                                                self.share_nw_dict['id'])
        self.assertEqual(len(share_nw_ref['security_services']), 0)
예제 #2
0
    def test_remove_security_service(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.security_service_create(self.fake_context, security_dict1)
        db_api.share_network_add_security_service(self.fake_context,
                                                  self.share_nw_dict['id'],
                                                  security_dict1['id'])

        db_api.share_network_remove_security_service(self.fake_context,
                                                     self.share_nw_dict['id'],
                                                     security_dict1['id'])

        result = 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(result is None)

        share_nw_ref = db_api.share_network_get(self.fake_context,
                                                self.share_nw_dict['id'])
        self.assertEqual(len(share_nw_ref['security_services']), 0)
예제 #3
0
    def remove_security_service(self, req, id, body):
        """Dissociate share network from a given security service."""
        context = req.environ['manila.context']
        share_network = db_api.share_network_get(context, id)
        policy.check_policy(context, RESOURCE_NAME, 'remove_security_service',
                            target_obj=share_network)
        data = body['remove_security_service']

        if self._share_network_subnets_contain_share_servers(share_network):
            msg = _("Cannot remove security services. Share network is used.")
            raise exc.HTTPForbidden(explanation=msg)
        try:
            share_network = db_api.share_network_remove_security_service(
                context,
                id,
                data['security_service_id'])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(explanation=e.msg)
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            raise exc.HTTPBadRequest(explanation=e.msg)

        return self._view_builder.build_share_network(req, share_network)
예제 #4
0
    def test_remove_security_service(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.security_service_create(self.fake_context, security_dict1)
        db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict["id"], security_dict1["id"])

        db_api.share_network_remove_security_service(self.fake_context, self.share_nw_dict["id"], security_dict1["id"])

        result = (
            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(result is None)

        share_nw_ref = db_api.share_network_get(self.fake_context, self.share_nw_dict["id"])
        self.assertEqual(len(share_nw_ref["security_services"]), 0)
예제 #5
0
    def _remove_security_service(self, req, id, data):
        """Dissociate share network from a given security service."""
        context = req.environ["manila.context"]
        policy.check_policy(context, RESOURCE_NAME, "remove_security_service")
        try:
            share_network = db_api.share_network_remove_security_service(context, id, data["security_service_id"])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            msg = "%s" % e
            raise exc.HTTPNotFound(explanation=msg)
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            msg = "%s" % e
            raise exc.HTTPBadRequest(explanation=msg)

        return self._view_builder.build_share_network(share_network)
예제 #6
0
    def _remove_security_service(self, req, id, data):
        """Dissociate share network from a given security service."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'remove_security_service')
        try:
            share_network = db_api.share_network_remove_security_service(
                context, id, data['security_service_id'])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            msg = "%s" % e
            raise exc.HTTPNotFound(explanation=msg)
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            msg = "%s" % e
            raise exc.HTTPBadRequest(explanation=msg)

        return self._view_builder.build_share_network(share_network)
예제 #7
0
    def _remove_security_service(self, req, id, data):
        """Dissociate share network from a given security service."""
        context = req.environ["manila.context"]
        policy.check_policy(context, RESOURCE_NAME, "remove_security_service")
        share_network = db_api.share_network_get(context, id)
        if share_network["share_servers"]:
            msg = _("Cannot remove security services. Share network is used.")
            raise exc.HTTPForbidden(explanation=msg)
        try:
            share_network = db_api.share_network_remove_security_service(context, id, data["security_service_id"])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))

        return self._view_builder.build_share_network(share_network)
예제 #8
0
    def _remove_security_service(self, req, id, data):
        """Dissociate share network from a given security service."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'remove_security_service')
        share_network = db_api.share_network_get(context, id)
        if share_network['share_servers']:
            msg = _("Cannot remove security services. Share network is used.")
            raise exc.HTTPForbidden(explanation=msg)
        try:
            share_network = db_api.share_network_remove_security_service(
                context, id, data['security_service_id'])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))

        return self._view_builder.build_share_network(req, share_network)