Browse Source

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
changes/80/820180/3
Thiago Brito 6 months ago
parent
commit
f5d836d161
  1. 93
      sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ilvg.py
  2. 2
      sysinv/cgts-client/cgts-client/cgtsclient/v1/ilvg.py

93
sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ilvg.py

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

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

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

Loading…
Cancel
Save