From f9a7febd46ebd8a28e26413f8d40338bffc99a8f Mon Sep 17 00:00:00 2001 From: Thiago Brito Date: Thu, 2 Dec 2021 14:56:03 -0300 Subject: [PATCH] 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] https://opendev.org/starlingx/config/commit/5923349485da0ea32042db1c60b0303f7d12e36d Partial-Bug: #1952400 Signed-off-by: Thiago Brito Change-Id: I0a8660ec530a859a6d108e5d85b808907c259614 --- .../cgtsclient/tests/v1/test_ipv.py | 60 +++++++++++++++++++ .../cgts-client/cgtsclient/v1/ipv.py | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ipv.py diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ipv.py b/sysinv/cgts-client/cgts-client/cgtsclient/tests/v1/test_ipv.py new file mode 100644 index 0000000000..4fc47bd3ac --- /dev/null +++ b/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) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ipv.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/ipv.py index 2a6b23a554..cb286f7b66 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ipv.py +++ b/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: