From 366ab2bfdb19d8b38c94dbf7cc52d5d660d22917 Mon Sep 17 00:00:00 2001 From: Shyam Singh Date: Thu, 28 May 2020 19:15:34 +0530 Subject: [PATCH] Upgrade for stable/rocky branch * Removed py36 env from 'tox.ini'. * Updated requirements.txt with relevant 'stable/rocky' branch libraries. * Updated test-requirements.txt with relevant 'stable/rocky' branch libraries. * Replaced 'mox' with 'mock' on unit tests. * Use stestr directly instead of ostestr to run UTs, as is done in newer upstream branches. * Specify basepython as python2.7 for pep8, cover jobs, in case a python3 version of tox is used. * Added 'flake8-import-order' and kept import-order-style as 'pep8'. * Added zuul jobs w.r.t. 'stable/rocky' release. * Removed '-U' option from toxenv install command, for stable/rocky & above branches compatibility. Change-Id: I9161749fb2d8618b695815c095bdedae0251bb76 --- .stestr.conf | 3 ++ .zuul.yaml | 30 ++++++++++++---- gbpclient/tests/unit/test_cli20.py | 58 ++++++++++++++++-------------- requirements.txt | 6 ++-- setup.cfg | 3 ++ test-requirements.txt | 11 +++--- tox.ini | 24 +++++++------ 7 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 .stestr.conf diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 0000000..745ebb6 --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=${OS_TEST_PATH:-./gbpclient/tests/unit} +top_dir=./ diff --git a/.zuul.yaml b/.zuul.yaml index 1788b9a..155b211 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -3,19 +3,37 @@ templates: - openstack-python-jobs - publish-to-pypi + # REVISIT: In the jobs below, the required-projects clause is needed on + # the master branch to select the correct version of the requirements + # repository. Otherwise, the master version will be used. It can be + # eliminated on the stable branches, and on the master branch once this + # repository's master branch is based on the neutron repository's master + # branch. check: jobs: - openstack-tox-pep8: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky - openstack-tox-py27: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky - openstack-tox-py35: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky gate: jobs: - openstack-tox-pep8: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky - openstack-tox-py27: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky - openstack-tox-py35: - nodeset: ubuntu-xenial + required-projects: + - name: openstack/requirements + override-checkout: stable/rocky diff --git a/gbpclient/tests/unit/test_cli20.py b/gbpclient/tests/unit/test_cli20.py index 2679679..b99b1c7 100644 --- a/gbpclient/tests/unit/test_cli20.py +++ b/gbpclient/tests/unit/test_cli20.py @@ -11,10 +11,11 @@ # under the License. # -from mox3 import mox +import mock +import requests + from neutronclient.common import exceptions from neutronclient.tests.unit import test_cli20 as neutron_test_cli20 -import requests from gbpclient import gbpshell from gbpclient.v2_0 import client as gbpclient @@ -65,9 +66,6 @@ class CLITestV20Base(neutron_test_cli20.CLITestV20Base): tenant_id=None, tags=None, admin_state_up=True, extra_body=None, cmd_resource=None, parent_id=None, **kwargs): - self.mox.StubOutWithMock(cmd, "get_client") - self.mox.StubOutWithMock(self.client.httpclient, "request") - cmd.get_client().MultipleTimes().AndReturn(self.client) if not cmd_resource: cmd_resource = resource body = {resource: {}, } @@ -91,17 +89,26 @@ class CLITestV20Base(neutron_test_cli20.CLITestV20Base): path = getattr(self.client, resource_plural + "_path") if parent_id: path = path % parent_id - mox_body = MyComparator(body, self.client) - self.client.httpclient.request( - end_url(path), 'POST', - body=mox_body, - headers=mox.ContainsKeyValue( - 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) - self.mox.ReplayAll() + mock_body = MyComparator(body, self.client) cmd_parser = cmd.get_parser('create_' + resource) - gbpshell.run_command(cmd, cmd_parser, args) - self.mox.VerifyAll() - self.mox.UnsetStubs() + resp = (MyResp(200), resstr) + + with mock.patch.object( + cmd, "get_client", return_value=self.client + ) as mock_get_client, mock.patch.object( + self.client.httpclient, "request", return_value=resp + ) as mock_request: + gbpshell.run_command(cmd, cmd_parser, args) + + self.assert_mock_multiple_calls_with_same_arguments( + mock_get_client, mock.call(), None) + + mock_request.assert_called_once_with( + end_url(path), 'POST', + body=mock_body, + headers=neutron_test_cli20.ContainsKeyValue( + {'X-Auth-Token': TOKEN})) + _str = self.fake_stdout.make_string() self.assertIn(myid, _str) if name: @@ -207,20 +214,19 @@ class CLITestV20ExceptionHandler(CLITestV20Base): self.assertEqual(e.status_code, 599) def test_connection_failed(self): - self.mox.StubOutWithMock(self.client.httpclient, 'request') self.client.httpclient.auth_token = 'token' + excp = requests.exceptions.ConnectionError('Connection refused') - self.client.httpclient.request( - end_url('/test'), 'GET', - headers=mox.ContainsKeyValue('X-Auth-Token', 'token') - ).AndRaise(requests.exceptions.ConnectionError('Connection refused')) + with mock.patch.object(self.client.httpclient, "request", + side_effect=excp) as mock_request: + error = self.assertRaises(exceptions.ConnectionFailed, + self.client.get, '/test') - self.mox.ReplayAll() - - error = self.assertRaises(exceptions.ConnectionFailed, - self.client.get, '/test') + mock_request.assert_called_once_with( + end_url('/test'), 'GET', + body=None, + headers=neutron_test_cli20.ContainsKeyValue( + {'X-Auth-Token': 'token'})) # NB: ConnectionFailed has no explicit status_code, so this # tests that there is a fallback defined. self.assertIsNotNone(error.status_code) - self.mox.VerifyAll() - self.mox.UnsetStubs() diff --git a/requirements.txt b/requirements.txt index 94cc1f1..9645e75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. pbr>=2.0.0,!=2.1.0 # Apache-2.0 -python-heatclient>=1.6.1 -python-neutronclient>=6.3.0,<6.8 -oslo.serialization>=2.18.0,!=2.19.1 # Apache-2.0 +python-heatclient>=1.10.0 # Apache-2.0 +python-neutronclient>=6.7.0 # Apache-2.0 +oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 2616a80..6d216f6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,3 +36,6 @@ source-dir = doc/source [wheel] universal = 1 + +[flake8] +import-order-style = pep8 diff --git a/test-requirements.txt b/test-requirements.txt index debb000..77aceb7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,19 +1,16 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking<0.11,>=0.10.0 +hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 -fixtures>=3.0.0 # Apache-2.0/BSD +flake8-import-order==0.12 # LGPLv3 httpretty>=0.8.0,!=0.8.1,!=0.8.2,!=0.8.3 -mox3>=0.20.0 # Apache-2.0 -mock>=2.0.0 # BSD oslotest>=3.2.0 # Apache-2.0 python-openstackclient>=3.12.0 # Apache-2.0 -python-subunit>=1.0.0 # Apache-2.0/BSD -reno>=2.5.0 # Apache-2.0 -requests-mock>=1.1.0 # Apache-2.0 sphinx!=1.6.6,>=1.6.2 # BSD +oslosphinx>=4.7.0 # Apache-2.0 +stestr>=1.0.0 # Apache-2.0 testrepository>=0.0.18 # Apache-2.0/BSD testtools>=2.2.0 # MIT testscenarios>=0.4 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index be6e29f..72f74dc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,22 +1,23 @@ [tox] -envlist = py27,py33,py36,pypy,pep8 -minversion = 1.6 +envlist = py27,py35,pypy,pep8 +minversion = 2.3.2 skipsdist = True [testenv] -basepython = python3 setenv = VIRTUAL_ENV={envdir} LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=C usedevelop = True -install_command = pip install -U {opts} {packages} -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = python setup.py testr --testr-args='{posargs}' +install_command = pip install {opts} {packages} +deps = + -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/rocky} + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = stestr run {posargs} [testenv:pep8] -basepython = python3 +basepython = python2.7 commands = flake8 distribute = false @@ -25,8 +26,11 @@ basepython = python3 commands = {posargs} [testenv:cover] -basepython = python3 -commands = python setup.py testr --coverage --testr-args='{posargs}' +basepython = python2.7 +commands = + coverage erase + coverage run -m testtools.run + coverage report --include="*gbpclient*" --omit="*test*" --omit="*.tox*" --omit="*nfp*" -m [testenv:docs] basepython = python3