Skip to content

Commit

Permalink
Get py34 subunit.run test discovery to work
Browse files Browse the repository at this point in the history
Currently the tox py34 target uses testtools.run to run
a subset of our test harness. We need to be able to use
pretty_tox.sh just like py27 as we make progress with py34
support.

The first step is to make sure we can discover all the
tests using:
python -m subunit.run discover -t . ./nova/tests/ --list

So, we need to fix a bunch of things for the discovery
to work including updating to a new version of websockify.

In the xen code, we should keep the original import and
add except for py34 as xen uses an older python that does
not work with six.moves.

Depends-On: Ib4ef2e79b28b7180e564b3d6dc2188456c66c08a
Change-Id: I88b6746da6136a7386a173f6cacd42f0b470deee
  • Loading branch information
dims committed Jul 28, 2015
1 parent 5bb1933 commit ed0196e
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 63 deletions.
4 changes: 4 additions & 0 deletions nova/api/openstack/api_version_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def __cmp__(self, other):
return cmp((self.ver_major, self.ver_minor),
(other.ver_major, other.ver_minor))

def __lt__(self, other):
return ((self.ver_major, self.ver_minor) <
(other.ver_major, other.ver_minor))

def matches(self, min_version, max_version):
"""Returns whether the version object represents a version
greater than or equal to the minimum version and less than
Expand Down
4 changes: 2 additions & 2 deletions nova/console/websocketproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
Leverages websockify.py by Joel Martin
'''

import Cookie
from six.moves import http_cookies as Cookie
import six.moves.urllib.parse as urlparse
import socket
import sys
import urlparse

from oslo_log import log as logging
import websockify
Expand Down
6 changes: 3 additions & 3 deletions nova/tests/unit/api/ec2/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import random
import re
import StringIO
from six.moves import StringIO

import boto
import boto.connection
Expand All @@ -28,7 +28,7 @@
if hasattr(boto.connection, 'HTTPResponse'):
httplib = boto.connection
else:
import httplib
from six.moves import http_client as httplib
import fixtures
from oslo_utils import versionutils
import webob
Expand All @@ -47,7 +47,7 @@ class FakeHttplibSocket(object):
"""a fake socket implementation for httplib.HTTPResponse, trivial."""
def __init__(self, response_string):
self.response_string = response_string
self._buffer = StringIO.StringIO(response_string)
self._buffer = StringIO(response_string)

def makefile(self, _mode, _other):
"""Returns the socket's internal buffer."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
ALL_IPS.append(sanitized)
for floating in fixed['floating_ips']:
ALL_IPS.append(floating)
ALL_IPS.sort()
ALL_IPS.sort(key=lambda x: str(x))


def fake_compute_get(*args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
sanitized['mac_address'] = cache['address']
sanitized.pop('type')
ALL_IPS.append(sanitized)
ALL_IPS.sort()
ALL_IPS.sort(key=lambda x: '%s-%s' % (x['address'], x['mac_address']))


def fake_compute_get(*args, **kwargs):
Expand Down
27 changes: 14 additions & 13 deletions nova/tests/unit/api/openstack/compute/contrib/test_hypervisors.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,32 +479,34 @@ def test_servers_non_admin_back_compatible_db(self):
self.TEST_HYPERS_OBJ[0].id)


_CELL_PATH = 'cell1'


class CellHypervisorsTestV21(HypervisorsTestV21):
cell_path = 'cell1'
TEST_HYPERS_OBJ = [cells_utils.ComputeNodeProxy(obj, cell_path)
TEST_HYPERS_OBJ = [cells_utils.ComputeNodeProxy(obj, _CELL_PATH)
for obj in TEST_HYPERS_OBJ]
TEST_SERVICES = [cells_utils.ServiceProxy(obj, cell_path)
TEST_SERVICES = [cells_utils.ServiceProxy(obj, _CELL_PATH)
for obj in TEST_SERVICES]

TEST_SERVERS = [dict(server,
host=cells_utils.cell_with_item(cell_path,
host=cells_utils.cell_with_item(_CELL_PATH,
server['host']))
for server in TEST_SERVERS]

DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV21.DETAIL_HYPERS_DICTS)
DETAIL_HYPERS_DICTS = [dict(hyp, id=cells_utils.cell_with_item(cell_path,
DETAIL_HYPERS_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
hyp['id']),
service=dict(hyp['service'],
id=cells_utils.cell_with_item(
cell_path,
_CELL_PATH,
hyp['service']['id']),
host=cells_utils.cell_with_item(
cell_path,
_CELL_PATH,
hyp['service']['host'])))
for hyp in DETAIL_HYPERS_DICTS]

INDEX_HYPER_DICTS = copy.deepcopy(HypervisorsTestV21.INDEX_HYPER_DICTS)
INDEX_HYPER_DICTS = [dict(hyp, id=cells_utils.cell_with_item(cell_path,
INDEX_HYPER_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
hyp['id']))
for hyp in INDEX_HYPER_DICTS]

Expand Down Expand Up @@ -559,21 +561,20 @@ def setUp(self):


class CellHypervisorsTestV2(HypervisorsTestV2, CellHypervisorsTestV21):
cell_path = 'cell1'
DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV2.DETAIL_HYPERS_DICTS)
DETAIL_HYPERS_DICTS = [dict(hyp, id=cells_utils.cell_with_item(cell_path,
DETAIL_HYPERS_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
hyp['id']),
service=dict(hyp['service'],
id=cells_utils.cell_with_item(
cell_path,
_CELL_PATH,
hyp['service']['id']),
host=cells_utils.cell_with_item(
cell_path,
_CELL_PATH,
hyp['service']['host'])))
for hyp in DETAIL_HYPERS_DICTS]

INDEX_HYPER_DICTS = copy.deepcopy(HypervisorsTestV2.INDEX_HYPER_DICTS)
INDEX_HYPER_DICTS = [dict(hyp, id=cells_utils.cell_with_item(cell_path,
INDEX_HYPER_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
hyp['id']))
for hyp in INDEX_HYPER_DICTS]

Expand Down
6 changes: 3 additions & 3 deletions nova/tests/unit/api/openstack/compute/test_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
Tests dealing with HTTP rate-limiting.
"""

import httplib
import StringIO
from six.moves import http_client as httplib
from six.moves import StringIO

import mock
from oslo_serialization import jsonutils
Expand Down Expand Up @@ -726,7 +726,7 @@ class FakeHttplibSocket(object):

def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
self._buffer = StringIO.StringIO(response_string)
self._buffer = StringIO(response_string)

def makefile(self, _mode, _other):
"""Returns the socket's internal buffer."""
Expand Down
4 changes: 2 additions & 2 deletions nova/tests/unit/cmd/test_baseproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def test_proxy_web_dir_does_not_exist(self, mock_exit, mock_exists):
@mock.patch('os.path.exists', return_value=True)
@mock.patch.object(logging, 'setup')
@mock.patch.object(gmr.TextGuruMeditation, 'setup_autorun')
@mock.patch.object(websocketproxy.NovaWebSocketProxy, '__init__',
@mock.patch('nova.console.websocketproxy.NovaWebSocketProxy.__init__',
return_value=None)
@mock.patch.object(websocketproxy.NovaWebSocketProxy, 'start_server')
@mock.patch('nova.console.websocketproxy.NovaWebSocketProxy.start_server')
def test_proxy(self, mock_start, mock_init, mock_gmr, mock_log,
mock_exists):
baseproxy.proxy('0.0.0.0', '6080')
Expand Down
6 changes: 3 additions & 3 deletions nova/tests/unit/image/test_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# under the License.

import datetime
import StringIO
from six.moves import StringIO

from nova import context
from nova import exception
Expand Down Expand Up @@ -108,10 +108,10 @@ def test_delete(self):

def test_create_then_get(self):
blob = 'some data'
s1 = StringIO.StringIO(blob)
s1 = StringIO(blob)
self.image_service.create(self.context,
{'id': '32', 'foo': 'bar'},
data=s1)
s2 = StringIO.StringIO()
s2 = StringIO()
self.image_service.download(self.context, '32', data=s2)
self.assertEqual(s2.getvalue(), blob, 'Did not get blob back intact')
4 changes: 2 additions & 2 deletions nova/tests/unit/image/test_glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


import datetime
import StringIO
from six.moves import StringIO

import glanceclient.exc
import mock
Expand Down Expand Up @@ -543,7 +543,7 @@ def test_download_data_dest_path_write_fails(self, show_mock, open_mock):
class FakeDiskException(Exception):
pass

class Exceptionator(StringIO.StringIO):
class Exceptionator(StringIO):
def write(self, _):
raise FakeDiskException('Disk full!')

Expand Down
2 changes: 1 addition & 1 deletion nova/tests/unit/image/test_transfer_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import urlparse
import six.moves.urllib.parse as urlparse

import mock

Expand Down
2 changes: 1 addition & 1 deletion nova/tests/unit/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

CONF = cfg.CONF

USER_DATA_STRING = ("This is an encoded string")
USER_DATA_STRING = (b"This is an encoded string")
ENCODE_USER_DATA_STRING = base64.b64encode(USER_DATA_STRING)


Expand Down
18 changes: 9 additions & 9 deletions nova/tests/unit/test_nova_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import StringIO
from six.moves import StringIO
import sys

import fixtures
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_unreserve_nonexistent_address(self):

def test_list(self):
self.useFixture(fixtures.MonkeyPatch('sys.stdout',
StringIO.StringIO()))
StringIO()))
self.commands.list()
self.assertNotEqual(1, sys.stdout.getvalue().find('192.168.0.100'))

Expand All @@ -71,7 +71,7 @@ def fake_fixed_ip_get_by_host(*args, **kwargs):
'nova.db.fixed_ip_get_by_host',
fake_fixed_ip_get_by_host))
self.useFixture(fixtures.MonkeyPatch('sys.stdout',
StringIO.StringIO()))
StringIO()))
self.commands.list('banana')
self.assertNotEqual(1, sys.stdout.getvalue().find('192.168.0.100'))

Expand Down Expand Up @@ -212,7 +212,7 @@ def test_list(self):
def fake_network_get_all(context):
return [db_fakes.FakeModel(self.net)]
self.stubs.Set(db, 'network_get_all', fake_network_get_all)
output = StringIO.StringIO()
output = StringIO()
sys.stdout = output
self.commands.list()
sys.stdout = sys.__stdout__
Expand Down Expand Up @@ -316,7 +316,7 @@ def setUp(self):
self.commands = manage.ProjectCommands()

def test_quota(self):
output = StringIO.StringIO()
output = StringIO()
sys.stdout = output
self.commands.quota(project_id='admin',
key='instances',
Expand All @@ -339,7 +339,7 @@ def setUp(self):
self.fake_flavor = objects.Flavor(**test_flavors.DEFAULT_FLAVORS[0])

def test_list_without_host(self):
output = StringIO.StringIO()
output = StringIO()
sys.stdout = output
with mock.patch.object(objects.InstanceList, 'get_by_filters') as get:
get.return_value = objects.InstanceList(
Expand All @@ -357,7 +357,7 @@ def test_list_without_host(self):
self.assertIn('foo-host', result)

def test_list_with_host(self):
output = StringIO.StringIO()
output = StringIO()
sys.stdout = output
with mock.patch.object(objects.InstanceList, 'get_by_host') as get:
get.return_value = objects.InstanceList(
Expand Down Expand Up @@ -387,15 +387,15 @@ def test_archive_deleted_rows_negative(self):
return_value={'foo': 0})
def test_null_instance_uuid_scan_no_records_found(self, mock_scan):
self.useFixture(fixtures.MonkeyPatch('sys.stdout',
StringIO.StringIO()))
StringIO()))
self.commands.null_instance_uuid_scan()
self.assertIn("There were no records found", sys.stdout.getvalue())

@mock.patch.object(migration, 'db_null_instance_uuid_scan',
return_value={'foo': 1, 'bar': 0})
def _test_null_instance_uuid_scan(self, mock_scan, delete):
self.useFixture(fixtures.MonkeyPatch('sys.stdout',
StringIO.StringIO()))
StringIO()))
self.commands.null_instance_uuid_scan(delete)
output = sys.stdout.getvalue()

Expand Down
10 changes: 5 additions & 5 deletions nova/tests/unit/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""Test of Policy Engine For Nova."""

import os.path
import StringIO
from six.moves import StringIO

import mock
import six.moves.urllib.request as urlrequest
Expand Down Expand Up @@ -100,17 +100,17 @@ def test_enforce_good_action(self):
result = policy.enforce(self.context, action, self.target)
self.assertEqual(result, True)

@mock.patch.object(urlrequest, 'urlopen',
return_value=StringIO.StringIO("True"))
@mock.patch.object(urlrequest, 'urlopen')
def test_enforce_http_true(self, mock_urlrequest):
mock_urlrequest.return_value = StringIO("True")
action = "example:get_http"
target = {}
result = policy.enforce(self.context, action, target)
self.assertEqual(result, True)

@mock.patch.object(urlrequest, 'urlopen',
return_value=StringIO.StringIO("False"))
@mock.patch.object(urlrequest, 'urlopen')
def test_enforce_http_false(self, mock_urlrequest):
mock_urlrequest.return_value = StringIO("False")
action = "example:get_http"
target = {}
self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
Expand Down
6 changes: 3 additions & 3 deletions nova/tests/unit/virt/libvirt/fake_libvirt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# under the License.

import os
import StringIO
from six.moves import StringIO

from nova.virt.libvirt import utils as libvirt_utils

Expand Down Expand Up @@ -137,9 +137,9 @@ def extract_snapshot(disk_path, source_fmt, out_path, dest_fmt):
class File(object):
def __init__(self, path, mode=None):
if path in files:
self.fp = StringIO.StringIO(files[path])
self.fp = StringIO(files[path])
else:
self.fp = StringIO.StringIO(files[os.path.split(path)[-1]])
self.fp = StringIO(files[os.path.split(path)[-1]])

def __enter__(self):
return self.fp
Expand Down
Loading

0 comments on commit ed0196e

Please sign in to comment.