Browse Source

Fixing variable renaming on _find_ipv

On commit [1] the 3rd parameter for _find_ipv() was renamed to fix a
lint issue, but the usage of that parameter wasn't correctly renamed and
a problem arised since there is a class in the same module with that
name (that was being shadowed before). This commit fixes that and add
some unitests for this method so we don't merge this kind of error in
the future.

[1]
5923349485

Partial-Bug: #1952400

Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: I0a8660ec530a859a6d108e5d85b808907c259614
changes/16/820216/1
Thiago Brito 6 months ago
parent
commit
f9a7febd46
  1. 60
      sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ipv.py
  2. 2
      sysinv/cgts-client/cgts-client/cgtsclient/v1/ipv.py

60
sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ipv.py

@ -0,0 +1,60 @@
#
# Copyright (c) 2021 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# -*- encoding: utf-8 -*-
#
import random
import mock
import testtools
import uuid
from cgtsclient import exc
from cgtsclient.v1 import ipv
class IPvTest(testtools.TestCase):
def test__find_ipv_numeric(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(random.randrange(1, 9))
ipv._find_ipv(mock_cc, mock_ihost, fake_id)
mock_cc.ipv.get.assert_called_with(fake_id)
mock_cc.ipv.list.assert_not_called()
def test__find_ipv_uuid(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(uuid.uuid4())
mock_cc.ipv.list.return_value = [
ipv.ipv(mock.MagicMock, info={
"uuid": fake_id
})
]
ilvg_found = ipv._find_ipv(mock_cc, mock_ihost, fake_id)
mock_cc.ipv.list.assert_called_with(mock_ihost.uuid)
self.assertEqual(fake_id, ilvg_found.uuid)
def test__find_ipv_uuid_not_found(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(uuid.uuid4())
mock_cc.ipv.list.return_value = []
self.assertRaisesRegexp(
exc.CommandError,
"physical volume not found: %s" % fake_id,
ipv._find_ipv,
mock_cc,
mock_ihost,
fake_id
)
mock_cc.ipv.list.assert_called_with(mock_ihost.uuid)

2
sysinv/cgts-client/cgts-client/cgtsclient/v1/ipv.py

@ -63,7 +63,7 @@ def _get_disks(cc, ihost, pv):
def _find_ipv(cc, ihost, ipv_id):
if ipv.isdigit():
if ipv_id.isdigit():
try:
pv = cc.ipv.get(ipv_id)
except exc.HTTPNotFound:

Loading…
Cancel
Save