Merge "Re-apply skipped cluster test"

This commit is contained in:
Zuul 2017-11-09 10:01:17 +00:00 committed by Gerrit Code Review
commit 6f04d52536
2 changed files with 36 additions and 23 deletions

View File

@ -65,35 +65,40 @@ def _mock_nsxlib():
'id': uuidutils.generate_uuid()}
for rule in rules
]}
mock.patch(
mocking = []
mocking.append(mock.patch(
"vmware_nsxlib.v3.cluster.NSXRequestsHTTPProvider"
".validate_connection").start()
".validate_connection"))
mock.patch(
mocking.append(mock.patch(
"vmware_nsxlib.v3.security.NsxLibNsGroup.create",
side_effect=_return_id_key
).start()
))
mock.patch(
mocking.append(mock.patch(
"vmware_nsxlib.v3.security.NsxLibFirewallSection.create_empty",
side_effect=_return_id_key).start()
side_effect=_return_id_key))
mock.patch(
mocking.append(mock.patch(
"vmware_nsxlib.v3.security.NsxLibFirewallSection.init_default",
side_effect=_return_id_key).start()
side_effect=_return_id_key))
mock.patch(
"vmware_nsxlib.v3.security.NsxLibNsGroup.list").start()
mocking.append(mock.patch(
"vmware_nsxlib.v3.security.NsxLibNsGroup.list"))
mock.patch(
mocking.append(mock.patch(
"vmware_nsxlib.v3.security.NsxLibFirewallSection.add_rules",
side_effect=_mock_add_rules_in_section).start()
side_effect=_mock_add_rules_in_section))
mock.patch(
mocking.append(mock.patch(
("vmware_nsxlib.v3.core_resources."
"NsxLibTransportZone.get_id_by_name_or_id"),
return_value=uuidutils.generate_uuid()).start()
return_value=uuidutils.generate_uuid()))
for m in mocking:
m.start()
return mocking
def get_default_nsxlib_config():
@ -141,7 +146,7 @@ class NsxLibTestCase(unittest.TestCase):
def setUp(self, *args, **kwargs):
super(NsxLibTestCase, self).setUp()
_mock_nsxlib()
self.mocking = _mock_nsxlib()
if self.use_client_cert_auth():
nsxlib_config = get_nsxlib_config_with_client_cert()
@ -153,6 +158,12 @@ class NsxLibTestCase(unittest.TestCase):
# print diffs when assert comparisons fail
self.maxDiff = None
def tearDown(self, *args, **kwargs):
# stop the mocks
for m in self.mocking:
m.stop()
super(NsxLibTestCase, self).tearDown()
class MemoryMockAPIProvider(nsx_cluster.AbstractHTTPProvider):
"""Acts as a HTTP provider for mocking which is backed

View File

@ -16,7 +16,6 @@
import unittest
import mock
from oslo_serialization import jsonutils
from requests import exceptions as requests_exceptions
from requests import models
import six.moves.urllib.parse as urlparse
@ -95,19 +94,22 @@ class RequestsHTTPProviderTestCase(unittest.TestCase):
self.assertEqual(99, session.timeout)
def test_validate_connection(self):
self.skipTest("Revist")
mock_conn = mocks.MockRequestSessionApi()
mock_conn.default_headers = {}
mock_ep = mock.Mock()
mock_ep.provider.url = 'https://1.2.3.4'
mock_cluster = mock.Mock()
mock_cluster.nsxlib_config = mock.Mock()
mock_cluster.nsxlib_config.url_base = 'abc'
mock_cluster.nsxlib_config.keepalive_section = 'transport-zones'
provider = cluster.NSXRequestsHTTPProvider()
self.assertRaises(nsxlib_exc.ResourceNotFound,
provider.validate_connection,
mock.Mock(), mock_ep, mock_conn)
mock_cluster, mock_ep, mock_conn)
mock_conn.post('api/v1/transport-zones',
data=jsonutils.dumps({'id': 'dummy-tz'}),
headers=client.JSONRESTClient._DEFAULT_HEADERS)
provider.validate_connection(mock.Mock(), mock_ep, mock_conn)
with mock.patch.object(client.JSONRESTClient, "get",
return_value={'result_count': 1}):
provider.validate_connection(mock_cluster, mock_ep, mock_conn)
class NsxV3ClusteredAPITestCase(nsxlib_testcase.NsxClientTestCase):