Fixing variable renaming

On commit [1] the 3rd parameter for _find_ilvg() 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: I328c3f5976f1903e621ff170a9da1a929983af18
This commit is contained in:
Thiago Brito 2021-12-02 11:50:45 -03:00
parent ed4a042a3e
commit f5d836d161
2 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,93 @@
#
# 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 ilvg
class ILvgTest(testtools.TestCase):
def test__find_ilvg_numeric(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(random.randrange(1, 9))
ilvg._find_ilvg(mock_cc, mock_ihost, fake_id)
mock_cc.ilvg.get.assert_called_with(fake_id)
mock_cc.ilvg.list.assert_not_called()
def test__find_ilvg_uuid(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(uuid.uuid4())
fake_name = "fake_ilvg"
mock_cc.ilvg.list.return_value = [
ilvg.ilvg(mock.MagicMock, info={
"uuid": fake_id, "lvm_vg_name": fake_name
})
]
ilvg_found = ilvg._find_ilvg(mock_cc, mock_ihost, fake_id)
mock_cc.ilvg.list.assert_called_with(mock_ihost.uuid)
self.assertEqual(fake_id, ilvg_found.uuid)
def test__find_ilvg_uuid_not_found(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(uuid.uuid4())
mock_cc.ilvg.list.return_value = []
self.assertRaisesRegexp(
exc.CommandError,
"Local volume group not found by name or uuid: %s" % fake_id,
ilvg._find_ilvg,
mock_cc,
mock_ihost,
fake_id
)
mock_cc.ilvg.list.assert_called_with(mock_ihost.uuid)
def test__find_ilvg_name(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_id = str(uuid.uuid4())
fake_name = "fake_ilvg"
mock_cc.ilvg.list.return_value = [
ilvg.ilvg(mock.MagicMock, info={
"uuid": fake_id, "lvm_vg_name": fake_name
})
]
ilvg_found = ilvg._find_ilvg(mock_cc, mock_ihost, fake_name)
mock_cc.ilvg.list.assert_called_with(mock_ihost.uuid)
self.assertEqual(fake_name, ilvg_found.lvm_vg_name)
def test__find_ilvg_name_not_found(self):
mock_cc = mock.MagicMock()
mock_ihost = mock.MagicMock()
fake_name = "fake_lvg_name"
mock_cc.ilvg.list.return_value = []
self.assertRaisesRegexp(
exc.CommandError,
"Local volume group not found by name or uuid: %s" % fake_name,
ilvg._find_ilvg,
mock_cc,
mock_ihost,
fake_name
)
mock_cc.ilvg.list.assert_called_with(mock_ihost.uuid)

View File

@ -55,7 +55,7 @@ class ilvgManager(base.Manager):
def _find_ilvg(cc, ihost, ilvg_id): def _find_ilvg(cc, ihost, ilvg_id):
if ilvg.isdigit(): if ilvg_id.isdigit():
try: try:
lvg = cc.ilvg.get(ilvg_id) lvg = cc.ilvg.get(ilvg_id)
except exc.HTTPNotFound: except exc.HTTPNotFound: