Glenn Van de Water 7741347041 Fix service discovery in functional tests
If a required service is not enabled then we skip the test.
The discovery is done by tests/functional/base.py:is_service_enabled
but this method is broken, credentials are not passed to the
'openstack service show' command so every call will fail and every test
that relies on it will be skipped. This commit fixed that method and
the issues that popped up when re-enabling tests.

Network segment range:
 - issue where we assumed network-segment-range extension is always
   present
 - issue where we compare integers and string representations of numbers

Subnet:
 - issue where we try to deepcopy an uncopyable object in UnsetSubnet

Change-Id: Id3cc907c1ed2a25b49cf6f4a7233e0401a02383a
Story: 2005169
Task: 29908
2019-03-13 16:16:24 +01:00

112 lines
3.5 KiB
Python

# Copyright (c) 2017, Intel Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from tempest.lib import exceptions as tempest_exc
from openstackclient.tests.functional import base
class ExtensionTests(base.TestCase):
"""Functional tests for extension"""
@classmethod
def setUpClass(cls):
super(ExtensionTests, cls).setUpClass()
cls.haz_network = cls.is_service_enabled('network')
def test_extension_list_compute(self):
"""Test compute extension list"""
json_output = json.loads(self.openstack(
'extension list -f json ' +
'--compute'
))
name_list = [item.get('Name') for item in json_output]
self.assertIn(
'ImageSize',
name_list,
)
def test_extension_list_volume(self):
"""Test volume extension list"""
json_output = json.loads(self.openstack(
'extension list -f json ' +
'--volume'
))
name_list = [item.get('Name') for item in json_output]
self.assertIn(
'TypesManage',
name_list,
)
def test_extension_list_network(self):
"""Test network extension list"""
if not self.haz_network:
self.skipTest("No Network service present")
json_output = json.loads(self.openstack(
'extension list -f json ' +
'--network'
))
name_list = [item.get('Name') for item in json_output]
self.assertIn(
'Default Subnetpools',
name_list,
)
# NOTE(dtroyer): Only network extensions are currently supported but
# I am going to leave this here anyway as a reminder
# fix that.
# def test_extension_show_compute(self):
# """Test compute extension show"""
# json_output = json.loads(self.openstack(
# 'extension show -f json ' +
# 'ImageSize'
# ))
# self.assertEqual(
# 'OS-EXT-IMG-SIZE',
# json_output.get('Alias'),
# )
def test_extension_show_network(self):
"""Test network extension show"""
if not self.haz_network:
self.skipTest("No Network service present")
name = 'agent'
json_output = json.loads(self.openstack(
'extension show -f json ' +
name
))
self.assertEqual(
name,
json_output.get('alias'),
)
def test_extension_show_not_exist(self):
"""Test extension show with not existed name"""
if not self.haz_network:
self.skipTest("No Network service present")
name = 'not_existed_ext'
try:
self.openstack('extension show ' + name)
except tempest_exc.CommandFailed as e:
self.assertIn('No Extension found for', str(e))
self.assertIn(name, str(e))
else:
self.fail('CommandFailed should be raised')