Switch baremetal nics/ports tests over
Moved baremetal port tests to a separate file and updated them to utilize the new testing method. Additionally, normalized the output of the port lists as noise is introduced that is not needed. Change-Id: I60492cca893e823cb2f9937405c75e23cc42807d
This commit is contained in:
parent
395d927081
commit
15263d36b3
@ -34,14 +34,16 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
||||
|
||||
def list_nics(self):
|
||||
with _utils.shade_exceptions("Error fetching machine port list"):
|
||||
return self.manager.submit_task(_tasks.MachinePortList())
|
||||
return self._normalize_machines(
|
||||
self.manager.submit_task(_tasks.MachinePortList()))
|
||||
|
||||
def list_nics_for_machine(self, uuid):
|
||||
with _utils.shade_exceptions(
|
||||
"Error fetching port list for node {node_id}".format(
|
||||
node_id=uuid)):
|
||||
return self.manager.submit_task(
|
||||
_tasks.MachineNodePortList(node_id=uuid))
|
||||
return self._normalize_machines(
|
||||
self.manager.submit_task(
|
||||
_tasks.MachineNodePortList(node_id=uuid)))
|
||||
|
||||
def get_nic_by_mac(self, mac):
|
||||
try:
|
||||
|
97
shade/tests/unit/test_baremetal_ports.py
Normal file
97
shade/tests/unit/test_baremetal_ports.py
Normal file
@ -0,0 +1,97 @@
|
||||
# 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.
|
||||
|
||||
"""
|
||||
test_baremetal_ports
|
||||
----------------------------------
|
||||
|
||||
Tests for baremetal port related operations
|
||||
"""
|
||||
|
||||
from testscenarios import load_tests_apply_scenarios as load_tests # noqa
|
||||
|
||||
from shade import exc
|
||||
from shade.tests import fakes
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestBaremetalPort(base.IronicTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBaremetalPort, self).setUp()
|
||||
self.fake_baremetal_node = fakes.make_fake_machine(
|
||||
self.name, self.uuid)
|
||||
# TODO(TheJulia): Some tests below have fake ports,
|
||||
# since they are required in some processes. Lets refactor
|
||||
# them at some point to use self.fake_baremetal_port.
|
||||
self.fake_baremetal_port = fakes.make_fake_port(
|
||||
'00:01:02:03:04:05',
|
||||
node_id=self.uuid)
|
||||
self.fake_baremetal_port2 = fakes.make_fake_port(
|
||||
'0a:0b:0c:0d:0e:0f',
|
||||
node_id=self.uuid)
|
||||
|
||||
def test_list_nics(self):
|
||||
port_list = [self.fake_baremetal_port,
|
||||
self.fake_baremetal_port2]
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(resource='ports'),
|
||||
json={'ports': [self.fake_baremetal_port,
|
||||
self.fake_baremetal_port2]}),
|
||||
])
|
||||
|
||||
return_value = self.op_cloud.list_nics()
|
||||
self.assertEqual(port_list, return_value)
|
||||
self.assert_calls()
|
||||
|
||||
def test_list_nics_failure(self):
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(resource='ports'),
|
||||
status_code=400)
|
||||
])
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.list_nics)
|
||||
self.assert_calls()
|
||||
|
||||
def test_list_nics_for_machine(self):
|
||||
port_list = [self.fake_baremetal_port,
|
||||
self.fake_baremetal_port2]
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
resource='nodes',
|
||||
append=[self.fake_baremetal_node['uuid'], 'ports']),
|
||||
json={'ports': [self.fake_baremetal_port,
|
||||
self.fake_baremetal_port2]}),
|
||||
])
|
||||
|
||||
return_value = self.op_cloud.list_nics_for_machine(
|
||||
self.fake_baremetal_node['uuid'])
|
||||
expected_value = port_list
|
||||
self.assertEqual(expected_value, return_value)
|
||||
self.assert_calls()
|
||||
|
||||
def test_list_nics_for_machine_failure(self):
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
resource='nodes',
|
||||
append=[self.fake_baremetal_node['uuid'], 'ports']),
|
||||
status_code=400)
|
||||
])
|
||||
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.list_nics_for_machine,
|
||||
self.fake_baremetal_node['uuid'])
|
||||
self.assert_calls()
|
@ -21,7 +21,6 @@ import os_client_config as occ
|
||||
from os_client_config import cloud_config
|
||||
import shade
|
||||
from shade import exc
|
||||
from shade import meta
|
||||
from shade.tests import fakes
|
||||
from shade.tests.unit import base
|
||||
|
||||
@ -34,37 +33,6 @@ class TestShadeOperator(base.RequestsMockTestCase):
|
||||
def test_operator_cloud(self):
|
||||
self.assertIsInstance(self.op_cloud, shade.OperatorCloud)
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'ironic_client')
|
||||
def test_list_nics(self, mock_client):
|
||||
port1 = fakes.FakeMachinePort(1, "aa:bb:cc:dd", "node1")
|
||||
port2 = fakes.FakeMachinePort(2, "dd:cc:bb:aa", "node2")
|
||||
port_list = [port1, port2]
|
||||
port_dict_list = meta.obj_list_to_munch(port_list)
|
||||
|
||||
mock_client.port.list.return_value = port_list
|
||||
nics = self.op_cloud.list_nics()
|
||||
|
||||
self.assertTrue(mock_client.port.list.called)
|
||||
self.assertEqual(port_dict_list, nics)
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'ironic_client')
|
||||
def test_list_nics_failure(self, mock_client):
|
||||
mock_client.port.list.side_effect = Exception()
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.list_nics)
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'ironic_client')
|
||||
def test_list_nics_for_machine(self, mock_client):
|
||||
mock_client.node.list_ports.return_value = []
|
||||
self.op_cloud.list_nics_for_machine("123")
|
||||
mock_client.node.list_ports.assert_called_with(node_id="123")
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'ironic_client')
|
||||
def test_list_nics_for_machine_failure(self, mock_client):
|
||||
mock_client.node.list_ports.side_effect = Exception()
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.list_nics_for_machine, None)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, '_image_client')
|
||||
def test_get_image_name(self, mock_client):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user