Fix continuation line under/over indented problems

When you are writing a multiple method invocation (or other similar
syntax)

```
obj.method(argument1,
           argument2,
           ...)
```

If you put argument1 in the first line, the following lines should have
the same hanging distance to argument1.

If you put argument1 in the second line, the hanging distance should
always be four.

```
obj.method(
    argument1,
    argument2,
    ...
)
```

Otherwise PEP8 would complain for continuation line under/over indented
problems. See below for more details

https://www.python.org/dev/peps/pep-0008/#indentation

This patch fixes all the continuation line indentation problems and
enables related checks in tox.ini.

Closes-bug: #1459514
Change-Id: I80995c2ae71b817ad78a87ab7c567f0d36112710
This commit is contained in:
Accela Zhao 2015-05-29 22:18:48 +08:00
parent 433403099a
commit 7344fcf2a7
63 changed files with 761 additions and 666 deletions

View File

@ -116,8 +116,7 @@ class V1(APIBase):
'http://docs.openstack.org',
'developer/magnum/dev',
'api-spec-v1.html',
bookmark=True, type='text/html')
]
bookmark=True, type='text/html')]
v1.media_types = [MediaType('application/json',
'application/vnd.openstack.magnum.v1+json')]
v1.pods = [link.Link.make_link('self', pecan.request.host_url,
@ -125,43 +124,37 @@ class V1(APIBase):
link.Link.make_link('bookmark',
pecan.request.host_url,
'pods', '',
bookmark=True)
]
bookmark=True)]
v1.rcs = [link.Link.make_link('self', pecan.request.host_url,
'rcs', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'rcs', '',
bookmark=True)
]
bookmark=True)]
v1.baymodels = [link.Link.make_link('self', pecan.request.host_url,
'baymodels', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)
]
bookmark=True)]
v1.bays = [link.Link.make_link('self', pecan.request.host_url,
'bays', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'bays', '',
bookmark=True)
]
bookmark=True)]
v1.containers = [link.Link.make_link('self', pecan.request.host_url,
'containers', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'containers', '',
bookmark=True)
]
bookmark=True)]
v1.services = [link.Link.make_link('self', pecan.request.host_url,
'services', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'services', '',
bookmark=True)
]
bookmark=True)]
return v1

View File

@ -120,8 +120,7 @@ class Bay(base.APIBase):
'bays', bay.uuid),
link.Link.make_link('bookmark', url,
'bays', bay.uuid,
bookmark=True)
]
bookmark=True)]
return bay
@classmethod
@ -193,7 +192,8 @@ class BaysController(rest.RestController):
marker_obj = objects.Bay.get_by_uuid(pecan.request.context,
marker)
bays = pecan.request.rpcapi.bay_list(pecan.request.context, limit,
bays = pecan.request.rpcapi.bay_list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)

View File

@ -131,7 +131,8 @@ class BayModel(base.APIBase):
@classmethod
def sample(cls, expand=True):
sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
sample = cls(
uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
name='example',
image_id='Fedora-k8s',
flavor_id='m1.small',
@ -314,7 +315,8 @@ class BayModelsController(rest.RestController):
baymodel_uuid)
try:
baymodel_dict = rpc_baymodel.as_dict()
baymodel = BayModel(**api_utils.apply_jsonpatch(baymodel_dict,
baymodel = BayModel(**api_utils.apply_jsonpatch(
baymodel_dict,
patch))
except api_utils.JSONPATCH_EXCEPTIONS as e:
raise exception.PatchError(patch=patch, reason=e)

View File

@ -103,12 +103,13 @@ class Container(base.APIBase):
container.unset_fields_except(['uuid', 'name', 'bay_uuid',
'image_id', 'command', 'status'])
container.links = [link.Link.make_link('self', url,
container.links = [link.Link.make_link(
'self', url,
'containers', container.uuid),
link.Link.make_link('bookmark', url,
link.Link.make_link(
'bookmark', url,
'containers', container.uuid,
bookmark=True)
]
bookmark=True)]
return container
@classmethod

View File

@ -79,8 +79,7 @@ class ReplicationController(v1_base.K8sResourceBase):
'rcs', rc.uuid),
link.Link.make_link('bookmark', url,
'rcs', rc.uuid,
bookmark=True)
]
bookmark=True)]
return rc
@classmethod
@ -220,11 +219,13 @@ class ReplicationControllersController(rest.RestController):
pecan.request.context,
marker)
rcs = pecan.request.rpcapi.rc_list(pecan.request.context, limit,
rcs = pecan.request.rpcapi.rc_list(
pecan.request.context, limit,
marker_obj, sort_key=sort_key,
sort_dir=sort_dir)
return ReplicationControllerCollection.convert_with_links(rcs, limit,
return ReplicationControllerCollection.convert_with_links(
rcs, limit,
url=resource_url,
expand=expand,
sort_key=sort_key,

View File

@ -95,13 +95,9 @@ class Service(v1_base.K8sResourceBase):
labels={'label1': 'foo'},
selector={'label1': 'foo'},
ip='172.17.2.2',
ports=[
{
"port": 88,
ports=[{"port": 88,
"targetPort": 6379,
"protocol": "TCP"
}
],
"protocol": "TCP"}],
manifest_url='file:///tmp/rc.yaml',
manifest='''{
"metadata": {

View File

@ -92,9 +92,11 @@ class Handler(object):
@staticmethod
def _docker_for_bay(bay):
tcp_url = 'tcp://%s:2376' % bay.api_address
return docker_client.DockerHTTPClient(tcp_url,
return docker_client.DockerHTTPClient(
tcp_url,
CONF.docker.docker_remote_api_version,
CONF.docker.default_timeout)
CONF.docker.default_timeout
)
@classmethod
def _docker_for_container(cls, context, container):

View File

@ -32,8 +32,8 @@ LOG = logging.getLogger(__name__)
kubernetes_opts = [
cfg.StrOpt('k8s_protocol',
default='http',
help=_('Default protocol of k8s master endpoint'
' (http or https).')),
help=_('Default protocol of k8s master endpoint '
'(http or https).')),
cfg.IntOpt('k8s_port',
default=8080,
help=_('Default port of the k8s master endpoint.')),

View File

@ -33,7 +33,7 @@ bay_heat_opts = [
cfg.StrOpt('cluster_coe',
default='kubernetes',
help=_('Container Orchestration Environments are '
'kubernetes or swarm. ')),
'kubernetes or swarm.'))
]
cfg.CONF.register_opts(bay_heat_opts, group='bay_heat')
@ -46,7 +46,6 @@ def upgrade():
baymodel = sa.sql.table('baymodel',
sa.sql.column('coe', sa.String(length=255)))
op.execute(
baymodel.update().values({'coe':
op.inline_literal(
cfg.CONF.bay_heat.cluster_coe)})
baymodel.update().values({
'coe': op.inline_literal(cfg.CONF.bay_heat.cluster_coe)})
)

View File

@ -599,7 +599,8 @@ class Connection(api.Connection):
# Prevent ironic_node_id overwriting
if values.get("ironic_node_id") and ref.ironic_node_id:
raise exception.NodeAssociated(node=node_id,
raise exception.NodeAssociated(
node=node_id,
instance=ref.ironic_node_id)
ref.update(values)

View File

@ -29,7 +29,8 @@ class TestRootController(tests.FunctionalTest):
self.assertEqual(expected, response.json)
def test_v1_controller(self):
expected = {u'media_types':
expected = {
u'media_types':
[{u'base': u'application/json',
u'type': u'application/vnd.openstack.magnum.v1+json'}],
u'links': [{u'href': u'http://localhost/v1/',

View File

@ -81,7 +81,8 @@ class TestListBay(api_base.FunctionalTest):
self.assertIn('node_addresses', response)
def test_get_one_by_name_not_found(self):
response = self.get_json('/bays/not_found',
response = self.get_json(
'/bays/not_found',
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -289,7 +290,8 @@ class TestPatch(api_base.FunctionalTest):
def test_add_ok(self):
name = 'bay_example_B'
response = self.patch_json('/bays/%s' % self.bay.uuid,
response = self.patch_json(
'/bays/%s' % self.bay.uuid,
[{'path': '/name', 'value': name, 'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_int)
@ -326,7 +328,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(self.bay.baymodel_id, response['baymodel_id'])
def test_add_non_existent_property(self):
response = self.patch_json('/bays/%s' % self.bay.uuid,
response = self.patch_json(
'/bays/%s' % self.bay.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -366,7 +369,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_remove_non_existent_property(self):
response = self.patch_json('/bays/%s' % self.bay.uuid,
response = self.patch_json(
'/bays/%s' % self.bay.uuid,
[{'path': '/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)

View File

@ -85,18 +85,22 @@ class TestListBayModel(api_base.FunctionalTest):
self.assertIn('coe', response)
def test_get_one_by_name_not_found(self):
response = self.get_json('/baymodels/not_found',
response = self.get_json(
'/baymodels/not_found',
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_get_one_by_name_multiple_baymodel(self):
obj_utils.create_test_baymodel(self.context, name='test_baymodel',
obj_utils.create_test_baymodel(
self.context, name='test_baymodel',
uuid=utils.generate_uuid())
obj_utils.create_test_baymodel(self.context, name='test_baymodel',
obj_utils.create_test_baymodel(
self.context, name='test_baymodel',
uuid=utils.generate_uuid())
response = self.get_json('/baymodels/test_baymodel',
response = self.get_json(
'/baymodels/test_baymodel',
expect_errors=True)
self.assertEqual(409, response.status_int)
self.assertEqual('application/json', response.content_type)
@ -125,7 +129,8 @@ class TestListBayModel(api_base.FunctionalTest):
def test_many(self):
bm_list = []
for id_ in range(5):
baymodel = obj_utils.create_test_baymodel(self.context, id=id_,
baymodel = obj_utils.create_test_baymodel(
self.context, id=id_,
uuid=utils.generate_uuid())
bm_list.append(baymodel.uuid)
response = self.get_json('/baymodels')
@ -170,7 +175,8 @@ class TestPatch(api_base.FunctionalTest):
def setUp(self):
super(TestPatch, self).setUp()
self.baymodel = obj_utils.create_test_baymodel(self.context,
self.baymodel = obj_utils.create_test_baymodel(
self.context,
name='bay_model_example_A',
image_id='nerdherd',
apiserver_port=8080,
@ -264,7 +270,8 @@ class TestPatch(api_base.FunctionalTest):
def test_add_root(self):
name = 'bay_model_example_B'
response = self.patch_json('/baymodels/%s' % self.baymodel.uuid,
response = self.patch_json(
'/baymodels/%s' % self.baymodel.uuid,
[{'path': '/name', 'value': name, 'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_int)
@ -282,7 +289,8 @@ class TestPatch(api_base.FunctionalTest):
response['coe'])
def test_add_root_non_existent(self):
response = self.patch_json('/baymodels/%s' % self.baymodel.uuid,
response = self.patch_json(
'/baymodels/%s' % self.baymodel.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)

View File

@ -171,7 +171,8 @@ class TestContainerController(db_base.DbTestCase):
response = self.app.get('/v1/containers/%s' % test_container['uuid'])
mock_container_get_by_uuid.assert_called_once_with(mock.ANY,
mock_container_get_by_uuid.assert_called_once_with(
mock.ANY,
test_container['uuid'])
self.assertEqual(response.status_int, 200)
self.assertEqual(response.json['uuid'],
@ -188,7 +189,8 @@ class TestContainerController(db_base.DbTestCase):
response = self.app.get('/v1/containers/%s' % test_container['name'])
mock_container_get_by_name.assert_called_once_with(mock.ANY,
mock_container_get_by_name.assert_called_once_with(
mock.ANY,
test_container['name'])
self.assertEqual(response.status_int, 200)
self.assertEqual(response.json['uuid'],

View File

@ -152,7 +152,8 @@ class TestPatch(api_base.FunctionalTest):
def test_add_ok(self):
new_image = 'Ubuntu'
response = self.patch_json('/nodes/%s' % self.node.uuid,
response = self.patch_json(
'/nodes/%s' % self.node.uuid,
[{'path': '/image_id', 'value': new_image, 'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_int)
@ -161,7 +162,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(new_image, response['image_id'])
def test_add_non_existent_property(self):
response = self.patch_json('/nodes/%s' % self.node.uuid,
response = self.patch_json(
'/nodes/%s' % self.node.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -189,7 +191,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_remove_non_existent_property(self):
response = self.patch_json('/nodes/%s' % self.node.uuid,
response = self.patch_json(
'/nodes/%s' % self.node.uuid,
[{'path': '/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(400, response.status_code)

View File

@ -194,7 +194,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_replace_internal_field(self):
response = self.patch_json('/pods/%s' % self.pod.uuid,
response = self.patch_json(
'/pods/%s' % self.pod.uuid,
[{'path': '/labels', 'value': {}, 'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -225,7 +226,8 @@ class TestPatch(api_base.FunctionalTest):
def test_add_ok(self):
new_desc = 'pod_example_B_desc'
response = self.patch_json('/pods/%s' % self.pod.uuid,
response = self.patch_json(
'/pods/%s' % self.pod.uuid,
[{'path': '/desc', 'value': new_desc, 'op': 'add'}])
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_int)
@ -261,7 +263,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(new_desc, response['desc'])
def test_add_non_existent_property(self):
response = self.patch_json('/pods/%s' % self.pod.uuid,
response = self.patch_json(
'/pods/%s' % self.pod.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -305,7 +308,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_remove_non_existent_property(self):
response = self.patch_json('/pods/%s' % self.pod.uuid,
response = self.patch_json(
'/pods/%s' % self.pod.uuid,
[{'path': '/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(400, response.status_code)

View File

@ -72,16 +72,19 @@ class TestListRC(api_base.FunctionalTest):
self._assert_rc_fields(response)
def test_get_one_by_name_not_found(self):
response = self.get_json('/rcs/not_found',
response = self.get_json(
'/rcs/not_found',
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_get_one_by_name_multiple_rc(self):
obj_utils.create_test_rc(self.context, name='test_rc',
obj_utils.create_test_rc(
self.context, name='test_rc',
uuid=utils.generate_uuid())
obj_utils.create_test_rc(self.context, name='test_rc',
obj_utils.create_test_rc(
self.context, name='test_rc',
uuid=utils.generate_uuid())
response = self.get_json('/rcs/test_rc', expect_errors=True)
self.assertEqual(409, response.status_int)
@ -151,7 +154,8 @@ class TestPatch(api_base.FunctionalTest):
obj_utils.create_test_bay(self.context)
self.rc = obj_utils.create_test_rc(self.context,
images=['rc_example_A_image'])
self.another_bay = obj_utils.create_test_bay(self.context,
self.another_bay = obj_utils.create_test_bay(
self.context,
uuid=utils.generate_uuid())
@mock.patch('oslo_utils.timeutils.utcnow')
@ -196,7 +200,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_replace_internal_field(self):
response = self.patch_json('/rcs/%s' % self.rc.uuid,
response = self.patch_json(
'/rcs/%s' % self.rc.uuid,
[{'path': '/labels', 'value': {}, 'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -238,7 +243,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(new_image, response['images'][0])
def test_add_non_existent_property(self):
response = self.patch_json('/rcs/%s' % self.rc.uuid,
response = self.patch_json(
'/rcs/%s' % self.rc.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -282,7 +288,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_remove_non_existent_property(self):
response = self.patch_json('/rcs/%s' % self.rc.uuid,
response = self.patch_json(
'/rcs/%s' % self.rc.uuid,
[{'path': '/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(400, response.status_code)

View File

@ -72,16 +72,19 @@ class TestListService(api_base.FunctionalTest):
self._assert_service_fields(response)
def test_get_one_by_name_not_found(self):
response = self.get_json('/services/not_found',
response = self.get_json(
'/services/not_found',
expect_errors=True)
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_get_one_by_name_multiple_service(self):
obj_utils.create_test_service(self.context, name='test_service',
obj_utils.create_test_service(
self.context, name='test_service',
uuid=utils.generate_uuid())
obj_utils.create_test_service(self.context, name='test_service',
obj_utils.create_test_service(
self.context, name='test_service',
uuid=utils.generate_uuid())
response = self.get_json('/services/test_service',
expect_errors=True)
@ -176,7 +179,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(response.json['error_message'])
def test_replace_internal_field(self):
response = self.patch_json('/services/%s' % self.service.uuid,
response = self.patch_json(
'/services/%s' % self.service.uuid,
[{'path': '/labels', 'value': {}, 'op': 'replace'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)
@ -206,7 +210,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertTrue(service_update.is_called)
def test_add_non_existent_property(self):
response = self.patch_json('/services/%s' % self.service.uuid,
response = self.patch_json(
'/services/%s' % self.service.uuid,
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual('application/json', response.content_type)

View File

@ -80,7 +80,8 @@ class TestJsonPatchType(base.FunctionalTest):
self.app = webtest.TestApp(MyRoot(['restjson']).wsgiapp())
def _patch_json(self, params, expect_errors=False):
return self.app.patch_json('/test', params=params,
return self.app.patch_json(
'/test', params=params,
headers={'Accept': 'application/json'},
expect_errors=expect_errors)

View File

@ -303,7 +303,8 @@ class GenericUtilsTestCase(base.TestCase):
self.assertEqual("abcd:ef01:2345:6789:abcd:ef01:c0a8:fefe",
utils.get_shortened_ipv6(
"abcd:ef01:2345:6789:abcd:ef01:192.168.254.254"))
self.assertEqual("::1", utils.get_shortened_ipv6(
self.assertEqual("::1",
utils.get_shortened_ipv6(
"0000:0000:0000:0000:0000:0000:0000:0001"))
self.assertEqual("caca::caca:0:babe:201:102",
utils.get_shortened_ipv6(
@ -314,9 +315,11 @@ class GenericUtilsTestCase(base.TestCase):
"failure")
def test_get_shortened_ipv6_cidr(self):
self.assertEqual("2600::/64", utils.get_shortened_ipv6_cidr(
self.assertEqual("2600::/64",
utils.get_shortened_ipv6_cidr(
"2600:0000:0000:0000:0000:0000:0000:0000/64"))
self.assertEqual("2600::/64", utils.get_shortened_ipv6_cidr(
self.assertEqual("2600::/64",
utils.get_shortened_ipv6_cidr(
"2600::1/64"))
self.assertRaises(netaddr.AddrFormatError,
utils.get_shortened_ipv6_cidr,

View File

@ -77,7 +77,8 @@ class TestKubeUtils(base.BaseTestCase):
mock_file.name = expected_filename
mock_named_tempfile.return_value.__enter__.return_value = mock_file
kube_utils._k8s_create_with_data(expected_api_address,
kube_utils._k8s_create_with_data(
expected_api_address,
expected_data)
mock_file.write.assert_called_once_with(expected_data)
@ -137,7 +138,8 @@ class TestKubeUtils(base.BaseTestCase):
mock_file.name = expected_filename
mock_named_tempfile.return_value.__enter__.return_value = mock_file
kube_utils._k8s_update_with_data(expected_api_address,
kube_utils._k8s_update_with_data(
expected_api_address,
expected_data)
mock_file.write.assert_called_once_with(expected_data)
@ -156,7 +158,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_create.return_value = ("", "")
@ -171,7 +173,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_create.return_value = ("", "create failed")
@ -186,7 +188,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_create.side_effect = Exception()
result = self.kube_client.pod_create(expected_api_address,
@ -200,7 +202,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_update.return_value = ("", "")
@ -215,7 +217,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_update.return_value = ("", "create failed")
@ -230,7 +232,7 @@ class KubeClientTestCase(base.TestCase):
expected_pod_content = mock.MagicMock(manifest='pod_content')
expected_command = [
expected_api_address,
expected_pod_content
expected_pod_content,
]
mock_k8s_update.side_effect = Exception()
result = self.kube_client.pod_update(expected_api_address,
@ -349,7 +351,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_update.return_value = ("", "")
@ -364,7 +366,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_update.return_value = ("", "create failed")
@ -379,7 +381,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_update.side_effect = Exception()
result = self.kube_client.service_update(expected_api_address,
@ -393,7 +395,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_create.return_value = ("", "")
@ -408,7 +410,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_create.return_value = ("", "create failed")
@ -423,7 +425,7 @@ class KubeClientTestCase(base.TestCase):
expected_service_content = mock.MagicMock(manifest='service_content')
expected_command = [
expected_api_address,
expected_service_content
expected_service_content,
]
mock_k8s_create.side_effect = Exception()
result = self.kube_client.service_create(expected_api_address,
@ -437,7 +439,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_update.return_value = ("", "")
@ -452,7 +454,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_update.return_value = ("", "update failed")
@ -467,7 +469,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_update.side_effect = Exception()
result = self.kube_client.rc_update(expected_api_address,
@ -481,7 +483,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_create.return_value = ("", "")
@ -496,7 +498,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_create.return_value = ("", "create failed")
@ -511,7 +513,7 @@ class KubeClientTestCase(base.TestCase):
expected_rc_content = mock.MagicMock(manifest='rc_content')
expected_command = [
expected_api_address,
expected_rc_content
expected_rc_content,
]
mock_k8s_create.side_effect = Exception()
result = self.kube_client.rc_create(expected_api_address,

View File

@ -64,7 +64,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(baymodel, fetched_baymodel)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition(self,
def test_extract_template_definition(
self,
mock_objects_baymodel_get_by_uuid):
baymodel = objects.BayModel(self.context, **self.baymodel_dict)
mock_objects_baymodel_get_by_uuid.return_value = baymodel
@ -89,7 +90,8 @@ class TestBayConductorWithK8s(base.TestCase):
@patch('requests.get')
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_coreos_with_disovery(self,
def test_extract_template_definition_coreos_with_disovery(
self,
mock_objects_baymodel_get_by_uuid,
reqget):
baymodel_dict = self.baymodel_dict
@ -124,7 +126,8 @@ class TestBayConductorWithK8s(base.TestCase):
@patch('uuid.uuid4')
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_coreos_no_discoveryurl(self,
def test_extract_template_definition_coreos_no_discoveryurl(
self,
mock_objects_baymodel_get_by_uuid,
mock_uuid):
baymodel_dict = self.baymodel_dict
@ -158,7 +161,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_dns(self,
def test_extract_template_definition_without_dns(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['dns_nameserver'] = None
@ -167,7 +171,8 @@ class TestBayConductorWithK8s(base.TestCase):
bay = objects.Bay(self.context, **self.bay_dict)
(template_path,
definition) = bay_conductor._extract_template_definition(self.context,
definition) = bay_conductor._extract_template_definition(
self.context,
bay)
expected = {
@ -183,7 +188,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_server_image(self,
def test_extract_template_definition_without_server_image(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['image_id'] = None
@ -192,7 +198,8 @@ class TestBayConductorWithK8s(base.TestCase):
bay = objects.Bay(self.context, **self.bay_dict)
(template_path,
definition) = bay_conductor._extract_template_definition(self.context,
definition) = bay_conductor._extract_template_definition(
self.context,
bay)
expected = {
@ -208,7 +215,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_minion_flavor(self,
def test_extract_template_definition_without_minion_flavor(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['flavor_id'] = None
@ -217,7 +225,8 @@ class TestBayConductorWithK8s(base.TestCase):
bay = objects.Bay(self.context, **self.bay_dict)
(template_path,
definition) = bay_conductor._extract_template_definition(self.context,
definition) = bay_conductor._extract_template_definition(
self.context,
bay)
expected = {
@ -233,7 +242,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_docker_volume_size(self,
def test_extract_template_definition_without_docker_volume_size(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['docker_volume_size'] = None
@ -258,7 +268,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_fixed_network(self,
def test_extract_template_definition_without_fixed_network(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['fixed_network'] = None
@ -283,7 +294,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_master_flavor(self,
def test_extract_template_definition_without_master_flavor(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['master_flavor_id'] = None
@ -292,7 +304,8 @@ class TestBayConductorWithK8s(base.TestCase):
bay = objects.Bay(self.context, **self.bay_dict)
(template_path,
definition) = bay_conductor._extract_template_definition(self.context,
definition) = bay_conductor._extract_template_definition(
self.context,
bay)
expected = {
@ -308,7 +321,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_ssh_authorized_key(self,
def test_extract_template_definition_without_ssh_authorized_key(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['cluster_distro'] = 'coreos'
@ -337,7 +351,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_apiserver_port(self,
def test_extract_template_definition_without_apiserver_port(
self,
mock_objects_baymodel_get_by_uuid):
baymodel_dict = self.baymodel_dict
baymodel_dict['apiserver_port'] = None
@ -346,7 +361,8 @@ class TestBayConductorWithK8s(base.TestCase):
bay = objects.Bay(self.context, **self.bay_dict)
(template_path,
definition) = bay_conductor._extract_template_definition(self.context,
definition) = bay_conductor._extract_template_definition(
self.context,
bay)
expected = {
@ -363,7 +379,8 @@ class TestBayConductorWithK8s(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_without_node_count(self,
def test_extract_template_definition_without_node_count(
self,
mock_objects_baymodel_get_by_uuid):
bay_dict = self.bay_dict
bay_dict['node_count'] = None
@ -397,16 +414,12 @@ class TestBayConductorWithK8s(base.TestCase):
expected_node_addresses = ['ex_minion', 'address']
outputs = [
{
"output_value": expected_node_addresses,
{"output_value": expected_node_addresses,
"description": "No description given",
"output_key": "kube_minions_external"
},
{
"output_value": expected_api_address,
"output_key": "kube_minions_external"},
{"output_value": expected_api_address,
"description": "No description given",
"output_key": "kube_master"
}
"output_key": "kube_master"}
]
mock_stack = mock.MagicMock()
mock_stack.outputs = outputs
@ -461,7 +474,8 @@ class TestBayConductorWithK8s(base.TestCase):
@patch('heatclient.common.template_utils.get_template_contents')
@patch('magnum.conductor.handlers.bay_conductor'
'._extract_template_definition')
def test_create_stack_no_timeout_specified(self,
def test_create_stack_no_timeout_specified(
self,
mock_extract_template_definition,
mock_get_template_contents,
mock_generate_id):
@ -501,7 +515,8 @@ class TestBayConductorWithK8s(base.TestCase):
@patch('heatclient.common.template_utils.get_template_contents')
@patch('magnum.conductor.handlers.bay_conductor'
'._extract_template_definition')
def test_create_stack_timeout_is_zero(self,
def test_create_stack_timeout_is_zero(
self,
mock_extract_template_definition,
mock_get_template_contents,
mock_generate_id):
@ -721,7 +736,8 @@ class TestHandler(db_base.DbTestCase):
@patch('magnum.conductor.handlers.bay_conductor.Handler._poll_and_check')
@patch('magnum.conductor.handlers.bay_conductor._update_stack')
@patch('magnum.common.clients.OpenStackClients')
def test_update_node_count_success(self, mock_openstack_client_class,
def test_update_node_count_success(
self, mock_openstack_client_class,
mock_update_stack, mock_poll_and_check):
mock_heat_stack = mock.MagicMock()
mock_heat_stack.stack_status = bay_status.CREATE_COMPLETE
@ -742,7 +758,8 @@ class TestHandler(db_base.DbTestCase):
@patch('magnum.conductor.handlers.bay_conductor.Handler._poll_and_check')
@patch('magnum.conductor.handlers.bay_conductor._update_stack')
@patch('magnum.common.clients.OpenStackClients')
def test_update_node_count_failure(self, mock_openstack_client_class,
def test_update_node_count_failure(
self, mock_openstack_client_class,
mock_update_stack, mock_poll_and_check):
mock_heat_stack = mock.MagicMock()
mock_heat_stack.stack_status = bay_status.CREATE_FAILED
@ -804,7 +821,8 @@ class TestBayConductorWithSwarm(base.TestCase):
}
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_all_values(self,
def test_extract_template_definition_all_values(
self,
mock_objects_baymodel_get_by_uuid):
baymodel = objects.BayModel(self.context, **self.baymodel_dict)
mock_objects_baymodel_get_by_uuid.return_value = baymodel
@ -827,7 +845,8 @@ class TestBayConductorWithSwarm(base.TestCase):
self.assertEqual(expected, definition)
@patch('magnum.objects.BayModel.get_by_uuid')
def test_extract_template_definition_only_required(self,
def test_extract_template_definition_only_required(
self,
mock_objects_baymodel_get_by_uuid):
cfg.CONF.set_override('public_swarm_discovery', False, group='bay')
cfg.CONF.set_override('swarm_discovery_url_format',

View File

@ -113,7 +113,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_container.image_id = 'test_image:some_tag'
mock_container.command = None
container = self.conductor.container_create(None, 'some-name',
container = self.conductor.container_create(
None, 'some-name',
'some-uuid', mock_container)
utf8_image_id = self.conductor._encode_utf8(mock_container.image_id)
@ -136,7 +137,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_container.image_id = 'test_image:some_tag'
mock_container.command = 'env'
container = self.conductor.container_create(None, 'some-name',
container = self.conductor.container_create(
None, 'some-name',
'some-uuid', mock_container)
utf8_image_id = self.conductor._encode_utf8(mock_container.image_id)
@ -158,8 +160,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_container.image_id = 'test_image:some_tag'
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.pull = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.pull = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_create,
@ -198,7 +200,8 @@ class TestDockerConductor(base.BaseTestCase):
@patch.object(docker_conductor.Handler, '_find_container_by_name')
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
def test_container_delete_with_container_not_exist(self,
def test_container_delete_with_container_not_exist(
self,
mock_get_docker_client,
mock_find_container):
mock_docker = mock.MagicMock()
@ -214,7 +217,8 @@ class TestDockerConductor(base.BaseTestCase):
@patch.object(docker_conductor.Handler, '_find_container_by_name')
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
def test_container_delete_with_failure(self,
def test_container_delete_with_failure(
self,
mock_get_docker_client,
mock_find_container):
mock_docker = mock.MagicMock()
@ -224,8 +228,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.remove_container = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.remove_container = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_delete,
None, mock_container_uuid)
@ -282,8 +286,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.restart = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.restart = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_reboot,
@ -323,8 +327,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.start = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.start = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_start,
@ -363,8 +367,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.stop = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.stop = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_stop,
@ -403,8 +407,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.pause = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.pause = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_pause,
@ -444,8 +448,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.unpause = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.unpause = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_unpause,
@ -567,8 +571,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.inspect_container = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.inspect_container = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_show,
None, mock_container_uuid)
@ -593,8 +597,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='404 error') as mock_init:
mock_docker.inspect_container = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.inspect_container = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.conductor.container_show(None, mock_container_uuid)
mock_docker.inspect_container.assert_called_once_with(
mock_docker_id)
@ -635,13 +639,14 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.exec_create = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.exec_create = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_execute,
None, mock_container_uuid, 'ls')
mock_docker.exec_create.assert_called_once_with(mock_docker_id,
'ls', True, True, False)
'ls', True, True,
False)
mock_find_container.assert_called_once_with(mock_docker,
mock_container_uuid)
mock_init.assert_called_once_with()
@ -672,8 +677,8 @@ class TestDockerConductor(base.BaseTestCase):
mock_find_container.return_value = mock_docker_id
with patch.object(errors.APIError, '__str__',
return_value='hit error') as mock_init:
mock_docker.get_container_logs = mock.Mock(side_effect=
errors.APIError('Error', '', ''))
mock_docker.get_container_logs = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
self.assertRaises(exception.ContainerException,
self.conductor.container_logs,
None, mock_container_uuid)

View File

@ -66,7 +66,8 @@ class TestKube(base.TestCase):
@patch('magnum.objects.Bay.get_by_uuid')
@patch('magnum.objects.BayModel.get_by_uuid')
def test_retrieve_k8s_master_url_from_pod(self,
def test_retrieve_k8s_master_url_from_pod(
self,
mock_baymodel_get_by_uuid,
mock_bay_get_by_uuid):
expected_context = 'context'
@ -93,7 +94,8 @@ class TestKube(base.TestCase):
@patch('magnum.objects.Bay.get_by_uuid')
@patch('magnum.objects.BayModel.get_by_uuid')
def test_retrieve_k8s_master_url_without_baymodel_apiserver_port(self,
def test_retrieve_k8s_master_url_without_baymodel_apiserver_port(
self,
mock_baymodel_get_by_uuid,
mock_bay_get_by_uuid):
expected_context = 'context'
@ -160,7 +162,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('ast.literal_eval')
def test_pod_create_fail_on_existing_pod(self, mock_literal_eval,
def test_pod_create_fail_on_existing_pod(
self, mock_literal_eval,
mock_retrieve_k8s_master_url):
expected_master_url = 'api_address'
expected_pod = self.mock_pod()
@ -198,7 +201,8 @@ class TestKube(base.TestCase):
self.kube_handler.pod_delete(self.context, mock_pod.uuid)
mock_kube_api.deletePod.assert_called_once_with(name=mock_pod.name,
mock_kube_api.deletePod.assert_called_once_with(
name=mock_pod.name,
namespaces='default')
mock_pod.destroy.assert_called_once_with(self.context)
@ -227,7 +231,8 @@ class TestKube(base.TestCase):
self.assertRaises(exception.KubernetesAPIFailed,
self.kube_handler.pod_delete,
self.context, mock_pod.uuid)
mock_kube_api.deletePod.assert_called_once_with(name=mock_pod.name,
mock_kube_api.deletePod.assert_called_once_with(
name=mock_pod.name,
namespaces='default')
self.assertFalse(mock_pod.destroy.called)
@ -235,7 +240,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('magnum.objects.Pod.get_by_uuid')
@patch('ast.literal_eval')
def test_pod_delete_succeeds_when_not_found(self, mock_literal_eval,
def test_pod_delete_succeeds_when_not_found(
self, mock_literal_eval,
mock_pod_get_by_uuid,
mock_retrieve_k8s_master_url,
mock_object_has_stack):
@ -303,7 +309,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._object_has_stack')
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('magnum.objects.Service.get_by_uuid')
def test_service_delete_with_success(self,
def test_service_delete_with_success(
self,
mock_service_get_by_uuid,
mock_retrieve_k8s_master_url,
mock_object_has_stack):
@ -327,7 +334,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('magnum.objects.Service.get_by_uuid')
@patch('ast.literal_eval')
def test_service_delete_with_failure(self, mock_literal_eval,
def test_service_delete_with_failure(
self, mock_literal_eval,
mock_service_get_by_uuid,
mock_retrieve_k8s_master_url,
mock_object_has_stack):
@ -357,7 +365,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('magnum.objects.Service.get_by_uuid')
@patch('ast.literal_eval')
def test_service_delete_succeeds_when_not_found(self, mock_literal_eval,
def test_service_delete_succeeds_when_not_found(
self, mock_literal_eval,
mock_service_get_by_uuid,
mock_retrieve_k8s_master_url,
mock_object_has_stack):
@ -478,7 +487,8 @@ class TestKube(base.TestCase):
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
@patch('magnum.objects.ReplicationController.get_by_uuid')
@patch('ast.literal_eval')
def test_rc_delete_succeeds_when_not_found(self, mock_literal_eval,
def test_rc_delete_succeeds_when_not_found(
self, mock_literal_eval,
mock_rc_get_by_uuid,
mock_retrieve_k8s_master_url,
mock_object_has_stack):

View File

@ -61,7 +61,8 @@ class BayLockTest(base.TestCase):
mock_object_create.assert_called_once_with(self.bay.uuid,
self.conductor_id)
mock_object_steal.assert_called_once_with(self.bay.uuid,
mock_object_steal.assert_called_once_with(
self.bay.uuid,
'fake-conductor-id', self.conductor_id)
@patch('magnum.objects.BayLock.create', return_value='fake-conductor-id')
@ -85,7 +86,8 @@ class BayLockTest(base.TestCase):
mock_object_create.assert_called_once_with(self.bay.uuid,
self.conductor_id)
mock_object_steal.assert_called_once_with(self.bay.uuid,
mock_object_steal.assert_called_once_with(
self.bay.uuid,
'fake-conductor-id', self.conductor_id)
@patch('magnum.objects.BayLock.steal', side_effect=[True, None])

View File

@ -50,22 +50,28 @@ class TemplateDefinitionTestCase(base.TestCase):
tdef.CoreOSK8sTemplateDefinition)
def test_get_vm_atomic_kubernetes_definition(self):
definition = tdef.TemplateDefinition.get_template_definition('vm',
'fedora-atomic', 'kubernetes')
definition = tdef.TemplateDefinition.get_template_definition(
'vm',
'fedora-atomic',
'kubernetes')
self.assertIsInstance(definition,
tdef.AtomicK8sTemplateDefinition)
def test_get_vm_coreos_kubernetes_definition(self):
definition = tdef.TemplateDefinition.get_template_definition('vm',
'coreos', 'kubernetes')
definition = tdef.TemplateDefinition.get_template_definition(
'vm',
'coreos',
'kubernetes')
self.assertIsInstance(definition,
tdef.CoreOSK8sTemplateDefinition)
def test_get_vm_atomic_swarm_definition(self):
definition = tdef.TemplateDefinition.get_template_definition('vm',
'fedora-atomic', 'swarm')
definition = tdef.TemplateDefinition.get_template_definition(
'vm',
'fedora-atomic',
'swarm')
self.assertIsInstance(definition,
tdef.AtomicSwarmTemplateDefinition)

View File

@ -78,10 +78,12 @@ class DbBayTestCase(base.DbTestCase):
self.dbapi.create_baymodel(bm1)
self.dbapi.create_baymodel(bm2)
bay1 = utils.create_test_bay(name='bay-one',
bay1 = utils.create_test_bay(
name='bay-one',
uuid=magnum_utils.generate_uuid(),
baymodel_id=bm1['uuid'])
bay2 = utils.create_test_bay(name='bay-two',
bay2 = utils.create_test_bay(
name='bay-two',
uuid=magnum_utils.generate_uuid(),
baymodel_id=bm2['uuid'],
node_count=1)

View File

@ -42,10 +42,14 @@ class DbBaymodelTestCase(base.DbTestCase):
self.assertEqual(sorted(uuids), sorted(res_uuids))
def test_get_baymodel_list_with_filters(self):
bm1 = self._create_test_baymodel(id=1, name='bm-one',
bm1 = self._create_test_baymodel(
id=1,
name='bm-one',
uuid=magnum_utils.generate_uuid(),
image_id='image1')
bm2 = self._create_test_baymodel(id=2, name='bm-two',
bm2 = self._create_test_baymodel(
id=2,
name='bm-two',
uuid=magnum_utils.generate_uuid(),
image_id='image2')
@ -86,10 +90,12 @@ class DbBaymodelTestCase(base.DbTestCase):
self.assertEqual(bm['uuid'], res.uuid)
def test_get_baymodel_by_name_multiple_baymodel(self):
self._create_test_baymodel(id=1, name='bm',
self._create_test_baymodel(
id=1, name='bm',
uuid=magnum_utils.generate_uuid(),
image_id='image1')
self._create_test_baymodel(id=2, name='bm',
self._create_test_baymodel(
id=2, name='bm',
uuid=magnum_utils.generate_uuid(),
image_id='image2')
self.assertRaises(exception.Conflict, self.dbapi.get_baymodel_by_name,

View File

@ -72,9 +72,11 @@ class DbContainerTestCase(base.DbTestCase):
self.assertEqual(sorted(uuids), sorted(res_uuids))
def test_get_container_list_with_filters(self):
container1 = utils.create_test_container(name='container-one',
container1 = utils.create_test_container(
name='container-one',
uuid=magnum_utils.generate_uuid())
container2 = utils.create_test_container(name='container-two',
container2 = utils.create_test_container(
name='container-two',
uuid=magnum_utils.generate_uuid())
res = self.dbapi.get_container_list(self.context,

View File

@ -72,10 +72,12 @@ class DbNodeTestCase(base.DbTestCase):
self.assertEqual(sorted(uuids), sorted(res_uuids))
def test_get_node_list_with_filters(self):
node1 = utils.create_test_node(type='virt',
node1 = utils.create_test_node(
type='virt',
ironic_node_id=magnum_utils.generate_uuid(),
uuid=magnum_utils.generate_uuid())
node2 = utils.create_test_node(type='bare',
node2 = utils.create_test_node(
type='bare',
uuid=magnum_utils.generate_uuid())
res = self.dbapi.get_node_list(self.context, filters={'type': 'virt'})

View File

@ -91,11 +91,13 @@ class DbPodTestCase(base.DbTestCase):
self.dbapi.create_bay(bay1)
self.dbapi.create_bay(bay2)
pod1 = utils.create_test_pod(name='pod-one',
pod1 = utils.create_test_pod(
name='pod-one',
uuid=magnum_utils.generate_uuid(),
bay_uuid=bay1['uuid'],
status='status1')
pod2 = utils.create_test_pod(name='pod-two',
pod2 = utils.create_test_pod(
name='pod-two',
uuid=magnum_utils.generate_uuid(),
bay_uuid=bay2['uuid'],
status='status2')

View File

@ -75,7 +75,8 @@ class DbRCTestCase(base.DbTestCase):
def test_get_rc_list(self):
uuids = [self.rc.uuid]
for i in range(1, 6):
rc = utils.create_test_rc(bay_uuid=self.bay.uuid,
rc = utils.create_test_rc(
bay_uuid=self.bay.uuid,
uuid=magnum_utils.generate_uuid())
uuids.append(six.text_type(rc.uuid))
rc = self.dbapi.get_rc_list(self.context)

View File

@ -75,7 +75,8 @@ class DbServiceTestCase(base.DbTestCase):
def test_get_service_list(self):
uuids = [self.service.uuid]
for i in range(1, 6):
service = utils.create_test_service(bay_uuid=self.bay.uuid,
service = utils.create_test_service(
bay_uuid=self.bay.uuid,
uuid=magnum_utils.generate_uuid())
uuids.append(six.text_type(service.uuid))
res = self.dbapi.get_service_list(self.context)
@ -88,11 +89,13 @@ class DbServiceTestCase(base.DbTestCase):
self.dbapi.create_bay(bay1)
self.dbapi.create_bay(bay2)
service1 = utils.create_test_service(name='service-one',
service1 = utils.create_test_service(
name='service-one',
uuid=magnum_utils.generate_uuid(),
bay_uuid=bay1['uuid'],
ports=[{'port': 8000}])
service2 = utils.create_test_service(name='service-two',
service2 = utils.create_test_service(
name='service-two',
uuid=magnum_utils.generate_uuid(),
bay_uuid=bay2['uuid'],
ports=[{'port': 8001}])

View File

@ -40,7 +40,8 @@ class TestBayLockObject(base.DbTestCase):
new_conductor_id = str(uuid.uuid4())
objects.BayLock.steal(self.bay_uuid, old_conductor_id,
new_conductor_id)
mock_steal_baylock.assert_called_once_with(self.bay_uuid,
mock_steal_baylock.assert_called_once_with(
self.bay_uuid,
old_conductor_id, new_conductor_id)
def test_release(self):

View File

@ -333,8 +333,7 @@ class _TestObject(object):
['created_at', 'updated_at'],
'magnum_object.data':
{'created_at': timeutils.isotime(dt),
'updated_at': timeutils.isotime(dt),
}
'updated_at': timeutils.isotime(dt)}
}
actual = obj.obj_to_primitive()
# magnum_object.changes is built from a set and order is undefined

View File

@ -52,7 +52,7 @@ commands =
# New from hacking 0.9: E129, E131, H407, H405, H904
# E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H302,H405,H803,H904,E711
ignore = E121,E122,E123,E124,E125,E131,E251,H302,H405,H803,H904,E711
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,magnum/common/pythonk8sclient
[testenv:pip-missing-reqs]