1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import testtools
from testtools import matchers
from cyborgclient.tests.unit import utils
from cyborgclient.v1 import deployables
DEPLOYABLE1 = {
"instance_uuid": "", "assignable": True,
"vendor": "test_vendor1",
"parent_uuid": "1859ef92-90c9-462e-ba78-3fd8295aa390",
"links": [
{"href": "http://127.0.0.1:6666/v1/deployables/fake_uuid",
"rel": "self"
},
{"href": "http://127.0.0.1:6666/deployables/fake_uuid",
"rel": "bookmark"}],
"updated_at": "2018-07-27T13:07:14+00:00",
"interface_type": "pci",
"uuid": "1859ef92-90c9-462e-ba78-3fd8295aa390",
"name": "test_name1", "host": "host_test1",
"version": "1", "board": "test_board1",
"address": "test_addr1", "created_at": None,
"type": "pf", "availability": "1",
"root_uuid": "1859ef92-90c9-462e-ba78-3fd8295aa390"
}
DEPLOYABLE2 = {
"instance_uuid": None, "assignable": False,
"vendor": "test_vendor2",
"parent_uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f",
"links": [
{"href": "http://127.0.0.1:6666/v1/deployables/fake_uuid",
"rel": "self"},
{"href": "http://127.0.0.1:6666/deployables/fake_uuid",
"rel": "bookmark"}],
"updated_at": "2018-07-27T19:51:18+00:00",
"interface_type": "mdev",
"uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f",
"name": "test_name2", "host": "host_test2", "version": "2",
"board": "test_board2", "address": "test_addr2",
"created_at": None, "type": "vf", "availability": "1",
"root_uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f"
}
ALLOC_DEPLOYABLE1 = {
"instance_uuid": None, "assignable": False,
"vendor": "test_vendor2",
"parent_uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f",
"links": [
{"href": "http://127.0.0.1:6666/v1/deployables/fake_uuid",
"rel": "self"},
{"href": "http://127.0.0.1:6666/deployables/fake_uuid",
"rel": "bookmark"}],
"updated_at": "2018-07-27T19:51:18+00:00",
"interface_type": "mdev",
"uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f",
"name": "test_name2", "host": "host_test2", "version": "2",
"board": "test_board2", "address": "test_addr2",
"created_at": None, "type": "vf", "availability": "1",
"root_uuid": "5a7dfaf9-7f4e-42d0-bfac-b2f464110d9f"
}
fake_responses = {
'/v1/accelerators/deployables':
{
'GET': (
{},
{'deployables': [DEPLOYABLE1, DEPLOYABLE2]},
)
},
'/v1/accelerators/deployables/%s' % ALLOC_DEPLOYABLE1["uuid"]:
{
'PATCH': (
{"instance_uuid": "fake_instance_uuid"},
ALLOC_DEPLOYABLE1,
),
},
'/v1/accelerators/deployables?filters.field=limit&filters.value=2':
{
'GET': (
{},
{'deployables': [DEPLOYABLE1, DEPLOYABLE2]},
)
},
'/v1/accelerators/deployables?filters.field=marker&filters.value=%s' %
DEPLOYABLE1['uuid']:
{
'GET': (
{},
{'deployables': [DEPLOYABLE1, DEPLOYABLE2]},
)
}
}
class DeployableManagerTest(testtools.TestCase):
def setUp(self):
super(DeployableManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = deployables.DeployableManager(self.api)
def test_deployables_list(self):
deployables = self.mgr.list()
expect = [
('GET', '/v1/accelerators/deployables', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(deployables, matchers.HasLength(2))
def _test_deployables_list_with_filters(self, limit=None, marker=None,
sort_key=None, sort_dir=None,
expect=[], **add_filters):
deployables_filter = self.mgr.list(limit=limit, marker=marker,
sort_key=sort_key,
sort_dir=sort_dir, **add_filters)
self.assertEqual(expect, self.api.calls)
self.assertThat(deployables_filter, matchers.HasLength(2))
def test_deployables_list_with_limit(self):
expect = [
('GET', '/v1/accelerators/deployables?filters.field='
'limit&filters.value=2', {}, None),
]
self._test_deployables_list_with_filters(
limit=2,
expect=expect)
def test_deployables_list_with_marker(self):
expect = [
('GET', '/v1/accelerators/deployables?filters.field=marker&'
'filters.value=%s' % DEPLOYABLE1['uuid'],
{}, None),
]
self._test_deployables_list_with_filters(
marker=DEPLOYABLE1['uuid'],
expect=expect)
def test_deployables_allocation(self):
dep_for_alloc = copy.deepcopy(ALLOC_DEPLOYABLE1)
self.mgr.allocation(dep_for_alloc["uuid"], "fake_instance_uuid")
expect = [
('PATCH', '/v1/accelerators/deployables/%s' %
dep_for_alloc["uuid"],
{}, [{'op': 'replace',
'path': '/instance_uuid',
'value': 'fake_instance_uuid'}])
]
self.assertEqual(expect, self.api.calls)
def test_deployables_deallocation(self):
dep_for_dealloc = copy.deepcopy(ALLOC_DEPLOYABLE1)
self.mgr.deallocation(dep_for_dealloc["uuid"])
expect = [
('PATCH', '/v1/accelerators/deployables/%s' %
dep_for_dealloc["uuid"],
{}, [{'op': 'replace',
'path': '/instance_uuid',
'value': None}])
]
self.assertEqual(expect, self.api.calls)
|