Beispiel #1
0
    def create_port_binding(self, context, client, port_id, data):
        if port_id not in self._ports:
            return fake_requests.FakeResponse(404,
                                              content='Port %s not found' %
                                              port_id)

        port = self._ports[port_id]
        binding = copy.deepcopy(data['binding'])

        # NOTE(stephenfin): We don't allow changing of backend
        binding['vif_type'] = port['binding:vif_type']
        binding['vif_details'] = port['binding:vif_details']
        binding['vnic_type'] = port['binding:vnic_type']

        # the first binding is active by default
        if not self._port_bindings[port_id]:
            binding['status'] = 'ACTIVE'
        else:
            binding['status'] = 'INACTIVE'

        self._port_bindings[port_id][binding['host']] = binding

        return fake_requests.FakeResponse(
            200,
            content=jsonutils.dumps({'binding': binding}),
        )
Beispiel #2
0
 def _get_failure_response_if_port_or_binding_not_exists(
     self,
     port_id,
     host,
 ):
     if port_id not in self._ports:
         return fake_requests.FakeResponse(404,
                                           content='Port %s not found' %
                                           port_id)
     if host not in self._port_bindings[port_id]:
         return fake_requests.FakeResponse(
             404,
             content='Binding for host %s for port %s not found' %
             (host, port_id))
Beispiel #3
0
    def test_get_arqs_for_instance_exception(self, mock_cyborg_get):
        # If Cyborg returns an error code, raise exception
        _, bound_arqs = self._get_bound_arqs()
        instance_uuid = bound_arqs[0]['instance_uuid']

        resp = fake_requests.FakeResponse(404, content='')
        mock_cyborg_get.return_value = resp
        self.assertRaises(exception.AcceleratorRequestOpFailed,
                          self.client.get_arqs_for_instance, instance_uuid)
Beispiel #4
0
    def get_port_binding(self, context, client, port_id, host):
        failure = self._get_failure_response_if_port_or_binding_not_exists(
            port_id, host)
        if failure is not None:
            return failure

        binding = {"binding": self._port_bindings[port_id][host]}
        return fake_requests.FakeResponse(200,
                                          content=jsonutils.dumps(binding))
Beispiel #5
0
    def activate_port_binding(self, context, client, port_id, host):
        failure = self._get_failure_response_if_port_or_binding_not_exists(
            port_id, host)
        if failure is not None:
            return failure

        self._activate_port_binding(port_id, host)

        return fake_requests.FakeResponse(200)
Beispiel #6
0
    def delete_port_binding(self, context, client, port_id, host):
        failure = self._get_failure_response_if_port_or_binding_not_exists(
            port_id, host)
        if failure is not None:
            return failure

        del self._port_bindings[port_id][host]

        return fake_requests.FakeResponse(204)
Beispiel #7
0
    def test_unknown_id(self):
        """Test response 403.

        This indicates we don't have permissions. We fail open here
        and assume the project exists.

        """
        self.mock_adap.get.return_value = fake_requests.FakeResponse(403)
        self.assertTrue(identity.verify_project_id(mock.MagicMock(), "foo"))
        self.validate_common()
Beispiel #8
0
    def test_good_id(self):
        """Test response 200.

        This indicates we have permissions, and we have definitively
        found the project exists.

        """
        self.mock_adap.get.return_value = fake_requests.FakeResponse(200)
        self.assertTrue(identity.verify_project_id(mock.MagicMock(), "foo"))
        self.validate_common()
Beispiel #9
0
    def test_get_arq_by_uuid_not_found(self, mock_cyborg_get):
        _, bound_arqs = self._get_bound_arqs()
        arq_uuids = [arq['uuid'] for arq in bound_arqs]
        content = jsonutils.dumps({})
        resp = fake_requests.FakeResponse(404, content)
        mock_cyborg_get.return_value = resp

        self.assertRaises(exception.AcceleratorRequestOpFailed,
                self.client.get_arq_by_uuid,
                arq_uuids[0])
Beispiel #10
0
    def test_unknown_error(self):
        """Test some other return from keystone.

        If we got anything else, something is wrong on the keystone
        side. We don't want to fail on our side.

        """
        self.mock_adap.get.return_value = fake_requests.FakeResponse(
            500, content="Oh noes!")
        self.assertTrue(identity.verify_project_id(mock.MagicMock(), "foo"))
        self.validate_common()
Beispiel #11
0
    def test_no_project(self):
        """Test response 404.

        This indicates that we have permissions, and we have
        definitively found the project does not exist.

        """
        self.mock_adap.get.return_value = fake_requests.FakeResponse(404)
        self.assertRaises(webob.exc.HTTPBadRequest, identity.verify_project_id,
                          mock.MagicMock(), "foo")
        self.validate_common()
Beispiel #12
0
    def test_get_arqs_for_instance_exception_no_resp(self, mock_cyborg_get):
        # If Cyborg returns an error code, raise exception
        _, bound_arqs = self._get_bound_arqs()
        instance_uuid = bound_arqs[0]['instance_uuid']

        content = jsonutils.dumps({'noarqs': 'oops'})
        resp = fake_requests.FakeResponse(200, content)
        mock_cyborg_get.return_value = resp
        self.assertRaisesRegex(exception.AcceleratorRequestOpFailed,
                               'Cyborg returned no accelerator requests for ',
                               self.client.get_arqs_for_instance,
                               instance_uuid)
Beispiel #13
0
    def test_get_arq_by_uuid(self, mock_cyborg_get):
        _, bound_arqs = self._get_bound_arqs()
        arq_uuids = [arq['uuid'] for arq in bound_arqs]
        content = jsonutils.dumps({'arqs': bound_arqs[0]})
        resp = fake_requests.FakeResponse(200, content)
        mock_cyborg_get.return_value = resp

        ret_arqs = self.client.get_arq_by_uuid(arq_uuids[0])

        mock_cyborg_get.assert_called_once_with(
            "%s/%s" % (self.client.ARQ_URL, arq_uuids[0]))
        self.assertEqual(bound_arqs[0], ret_arqs['arqs'])
Beispiel #14
0
    def test_get_arqs_for_instance_some_resolved(self, mock_cyborg_get):
        # If only some ARQs are resolved, return just the resolved ones
        unbound_arqs, _ = self._get_arqs_and_request_groups()
        _, bound_arqs = self._get_bound_arqs()
        # Create a amixture of unbound and bound ARQs
        arqs = [unbound_arqs[0], bound_arqs[0]]
        instance_uuid = bound_arqs[0]['instance_uuid']

        query = {"instance": instance_uuid}
        content = jsonutils.dumps({'arqs': arqs})
        resp = fake_requests.FakeResponse(200, content)
        mock_cyborg_get.return_value = resp

        ret_arqs = self.client.get_arqs_for_instance(instance_uuid,
                                                     only_resolved=True)

        mock_cyborg_get.assert_called_once_with(self.client.ARQ_URL,
                                                params=query)
        self.assertEqual(ret_arqs, [bound_arqs[0]])
Beispiel #15
0
    def test_get_arqs_for_instance(self, mock_cyborg_get):
        # Happy path, without only_resolved=True
        _, bound_arqs = self._get_bound_arqs()
        instance_uuid = bound_arqs[0]['instance_uuid']

        query = {"instance": instance_uuid}
        content = jsonutils.dumps({'arqs': bound_arqs})
        resp = fake_requests.FakeResponse(200, content)
        mock_cyborg_get.return_value = resp

        ret_arqs = self.client.get_arqs_for_instance(instance_uuid)

        mock_cyborg_get.assert_called_once_with(self.client.ARQ_URL,
                                                params=query)

        bound_arqs.sort(key=lambda x: x['uuid'])
        ret_arqs.sort(key=lambda x: x['uuid'])
        for ret_arq, bound_arq in zip(ret_arqs, bound_arqs):
            self.assertDictEqual(ret_arq, bound_arq)
Beispiel #16
0
    def test_get_arq_uuids_for_instance(self, mock_cyborg_get):
        # Happy path, without only_resolved=True
        _, bound_arqs = self._get_bound_arqs()
        instance_uuid = bound_arqs[0]['instance_uuid']
        flavor = objects.Flavor(extra_specs={'accel:device_profile': 'dp1'})
        instance = objects.Instance(flavor=flavor, uuid=instance_uuid)
        query = {"instance": instance_uuid}
        content = jsonutils.dumps({'arqs': bound_arqs})
        resp = fake_requests.FakeResponse(200, content)
        mock_cyborg_get.return_value = resp

        ret_arqs = self.client.get_arq_uuids_for_instance(instance)

        mock_cyborg_get.assert_called_once_with(self.client.ARQ_URL,
                                                params=query)
        bound_arqs = [bound_arq['uuid'] for bound_arq in bound_arqs]
        bound_arqs.sort()
        ret_arqs.sort()
        self.assertEqual(bound_arqs, ret_arqs)