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
This commit is contained in:
Thiago Brito 2021-12-02 14:56:03 -03:00
parent f5d836d161
commit f9a7febd46
2 changed files with 61 additions and 1 deletions

View File

@ -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)

View File

@ -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: