示例#1
0
    return node


def fake_interface(**updates):
    interface = {
        'id': 1,
        'address': '11:11:11:11:11:11',
        'datapath_id': 2,
        'port_no': 3,
    }
    if updates:
        interface.update(updates)
    return interface


FAKE_IRONIC_CLIENT = ironic_utils.FakeClient()


@mock.patch.object(baremetal_nodes, '_get_ironic_client',
                   lambda *_: FAKE_IRONIC_CLIENT)
class BareMetalNodesTest(test.NoDBTestCase):
    def setUp(self):
        super(BareMetalNodesTest, self).setUp()

        self.ext_mgr = self.mox.CreateMock(extensions.ExtensionManager)
        self.context = context.get_admin_context()
        self.controller = baremetal_nodes.BareMetalNodeController(self.ext_mgr)
        self.request = FakeRequest(self.context)

    def _test_create(self, node, ext_status=False):
        response = node.copy()
#    License for the specific language governing permissions and limitations
#    under the License.

from ironicclient import client as ironic_client
from ironicclient import exc as ironic_exception
import mock
from oslo.config import cfg

from nova import exception
from nova import test
from nova.tests.virt.ironic import utils as ironic_utils
from nova.virt.ironic import client_wrapper

CONF = cfg.CONF

FAKE_CLIENT = ironic_utils.FakeClient()


class IronicClientWrapperTestCase(test.NoDBTestCase):
    def setUp(self):
        super(IronicClientWrapperTestCase, self).setUp()
        self.icli = client_wrapper.IronicClientWrapper()
        # Do not waste time sleeping
        cfg.CONF.set_override('api_retry_interval', 0, 'ironic')

    @mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
    @mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
    def test_call_good_no_args(self, mock_get_client, mock_multi_getattr):
        mock_get_client.return_value = FAKE_CLIENT
        self.icli.call("node.list")
        mock_get_client.assert_called_once_with()