+---------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+=======================================+===============+===========================================================+
- | test_create_stack_template_file | 1 | Ensures that a Heat stack can be created with a file-based|
+ | test_create_stack_template_file | 1-3 | Ensures that a Heat stack can be created with a file-based|
| | | Heat template file |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_create_stack_template_dict | 1 | Ensures that a Heat stack can be created with a dictionary|
+ | test_create_stack_template_dict | 1-3 | Ensures that a Heat stack can be created with a dictionary|
| | | Heat template |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_create_delete_stack | 1 | Ensures that a Heat stack can be created and deleted |
+ | test_create_delete_stack | 1-3 | Ensures that a Heat stack can be created and deleted |
| | | while having clean() called 2x without an exception |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_create_same_stack | 1 | Ensures that a Heat stack with the same name cannot be |
+ | test_create_same_stack | 1-3 | Ensures that a Heat stack with the same name cannot be |
| | | created 2x |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_retrieve_network_creators | 1 | Ensures that an OpenStackHeatStack instance can return an |
+ | test_retrieve_network_creators | 1-3 | Ensures that an OpenStackHeatStack instance can return an |
| | | OpenStackNetwork instance configured as deployed |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_retrieve_vm_inst_creators | 1 | Ensures that an OpenStackHeatStack instance can return an |
+ | test_retrieve_vm_inst_creators | 1-3 | Ensures that an OpenStackHeatStack instance can return an |
| | | OpenStackVmInstance instance configured as deployed |
+---------------------------------------+---------------+-----------------------------------------------------------+
+---------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+=======================================+===============+===========================================================+
- | test_retrieve_volume_creator | 1 | Ensures that an OpenStackHeatStack instance can return a |
+ | test_retrieve_volume_creator | 1-3 | Ensures that an OpenStackHeatStack instance can return a |
| | | OpenStackVolume instance that it was responsible for |
| | | deploying |
+---------------------------------------+---------------+-----------------------------------------------------------+
- | test_retrieve_volume_type_creator | 1 | Ensures that an OpenStackHeatStack instance can return a |
+ | test_retrieve_volume_type_creator | 1-3 | Ensures that an OpenStackHeatStack instance can return a |
| | | OpenStackVolumeType instance that it was responsible for |
| | | deploying |
+---------------------------------------+---------------+-----------------------------------------------------------+
+create_stack_tests.py - CreateStackFloatingIpTests
+--------------------------------------------------
+
++---------------------------------------+---------------+-----------------------------------------------------------+
+| Test Name | Heat API | Description |
++=======================================+===============+===========================================================+
+| test_connect_via_ssh_heat_vm | 1 | Ensures that an OpenStackHeatStack instance can create a |
+| | | VM with a floating IP that can be accessed via |
+| | | OpenStackVmInstance |
++---------------------------------------+---------------+-----------------------------------------------------------+
+
+create_stack_tests.py - CreateStackRouterTests
+----------------------------------------------
+
++---------------------------------------+---------------+-----------------------------------------------------------+
+| Test Name | Heat API | Description |
++=======================================+===============+===========================================================+
+| test_retrieve_router_creator | 1 | Ensures that an OpenStackHeatStack instance can return a |
+| | | OpenStackRouter instance that it was responsible for |
+| | | deploying |
++---------------------------------------+---------------+-----------------------------------------------------------+
+
create_stack_tests.py - CreateStackFlavorTests
----------------------------------------------
+---------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+=======================================+===============+===========================================================+
- | test_retrieve_flavor_creator | 1 | Ensures that an OpenStackHeatStack instance can return a |
+ | test_retrieve_flavor_creator | 1-3 | Ensures that an OpenStackHeatStack instance can return a |
| | | OpenStackFlavor instance that it was responsible for |
| | | deploying |
+---------------------------------------+---------------+-----------------------------------------------------------+
+---------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+=======================================+===============+===========================================================+
- | test_retrieve_keypair_creator | 1 | Ensures that an OpenStackHeatStack instance can return a |
+ | test_retrieve_keypair_creator | 1-3 | Ensures that an OpenStackHeatStack instance can return a |
| | | OpenStackKeypair instance that it was responsible for |
| | | deploying |
+---------------------------------------+---------------+-----------------------------------------------------------+
+---------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+=======================================+===============+===========================================================+
- | test_connect_via_ssh_heat_vm | 1 | Ensures that two OpenStackHeatStack instances can return |
+ | test_connect_via_ssh_heat_vm | 1-3 | Ensures that two OpenStackHeatStack instances can return |
| | | OpenStackVmInstance instances one configured with a |
| | | floating IP and keypair and can be access via SSH |
+---------------------------------------+---------------+-----------------------------------------------------------+
+----------------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Heat API | Description |
+========================================+===============+===========================================================+
- | test_missing_dependencies | 1 | Ensures that a Heat template fails to deploy when expected|
+ | test_missing_dependencies | 1-3 | Ensures that a Heat template fails to deploy when expected|
| | | dependencies are missing |
+----------------------------------------+---------------+-----------------------------------------------------------+
- | test_bad_stack_file | 1 | Ensures that a Heat template fails to deploy when the Heat|
+ | test_bad_stack_file | 1-3 | Ensures that a Heat template fails to deploy when the Heat|
| | | template file does not exist |
+----------------------------------------+---------------+-----------------------------------------------------------+
+ create_stack_tests.py - CreateStackFailureTests
+ -----------------------------------------------
+
+ +----------------------------------------+---------------+-----------------------------------------------------------+
+ | Test Name | Heat API | Description |
+ +========================================+===============+===========================================================+
+ | test_stack_failure | 1-3 | Ensures that a Heat template fails to deploy when expected|
+ | | | dependencies are missing |
+ +----------------------------------------+---------------+-----------------------------------------------------------+
+
create_instance_tests.py - CreateInstanceSimpleTests
----------------------------------------------------
# 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 os
import time
import pkg_resources
from heatclient.exc import HTTPBadRequest
from snaps import file_utils
from snaps.openstack.create_flavor import OpenStackFlavor, FlavorSettings
- from snaps.openstack.create_image import OpenStackImage
+ from snaps.openstack.create_image import OpenStackImage, ImageSettings
try:
from urllib.request import URLError
from snaps.openstack import create_stack
from snaps.openstack.create_stack import (
- StackSettings, StackSettingsError, StackCreationError)
+ StackSettings, StackSettingsError, StackCreationError, StackError)
from snaps.openstack.tests import openstack_tests, create_instance_tests
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import heat_utils, neutron_utils, nova_utils
class CreateStackSuccessTests(OSIntegrationTestCase):
"""
- Tests for the CreateStack class defined in create_stack.py
+ Tests for the OpenStackHeatStack class defined in create_stack.py
"""
def setUp(self):
- """
- Instantiates the CreateStack object that is responsible for downloading
- and creating an OS stack file within OpenStack
- """
+
super(self.__class__, self).__start__()
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
class CreateStackFloatingIpTests(OSIntegrationTestCase):
"""
- Tests for the CreateStack class defined in create_stack.py
+ Tests to ensure that floating IPs can be accessed via an
+ OpenStackVmInstance object obtained from the OpenStackHeatStack instance
"""
def setUp(self):
- """
- Instantiates the CreateStack object that is responsible for downloading
- and creating an OS stack file within OpenStack
- """
+
super(self.__class__, self).__start__()
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
self.assertEqual(0, len(vm_settings.floating_ip_settings))
+class CreateStackRouterTests(OSIntegrationTestCase):
+ """
+ Tests for the CreateStack class defined in create_stack.py where the
+ target is a Network, Subnet, and Router
+ """
+
+ def setUp(self):
+ """
+ Instantiates the CreateStack object that is responsible for downloading
+ and creating an OS stack file within OpenStack
+ """
+ super(self.__class__, self).__start__()
+
+ self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
+
+ self.heat_creds = self.admin_os_creds
+ self.heat_creds.project_name = self.admin_os_creds.project_name
+
+ self.heat_cli = heat_utils.heat_client(self.heat_creds)
+ self.neutron = neutron_utils.neutron_client(self.os_creds)
+ self.stack_creator = None
+
+ self.net_name = self.guid + '-net'
+ self.subnet_name = self.guid + '-subnet'
+ self.router_name = self.guid + '-router'
+
+ self.env_values = {
+ 'net_name': self.net_name,
+ 'subnet_name': self.subnet_name,
+ 'router_name': self.router_name,
+ 'external_net_name': self.ext_net_name}
+
+ self.heat_tmplt_path = pkg_resources.resource_filename(
+ 'snaps.openstack.tests.heat', 'router_heat_template.yaml')
+
+ stack_settings = StackSettings(
+ name=self.__class__.__name__ + '-' + str(self.guid) + '-stack',
+ template_path=self.heat_tmplt_path,
+ env_values=self.env_values)
+ self.stack_creator = create_stack.OpenStackHeatStack(
+ self.heat_creds, stack_settings)
+ self.created_stack = self.stack_creator.create()
+ self.assertIsNotNone(self.created_stack)
+
+ def tearDown(self):
+ """
+ Cleans the stack and downloaded stack file
+ """
+ if self.stack_creator:
+ try:
+ self.stack_creator.clean()
+ except:
+ pass
+
+ super(self.__class__, self).__clean__()
+
+ def test_retrieve_router_creator(self):
+ """
+ Tests the creation of an OpenStack stack from Heat template file and
+ the retrieval of an OpenStackRouter creator/state machine instance
+ """
+ router_creators = self.stack_creator.get_router_creators()
+ self.assertEqual(1, len(router_creators))
+
+ creator = router_creators[0]
+ self.assertEqual(self.router_name, creator.router_settings.name)
+
+ router = creator.get_router()
+
+ ext_net = neutron_utils.get_network(
+ self.neutron, network_name=self.ext_net_name)
+ self.assertEqual(ext_net.id, router.external_network_id)
+
+
class CreateStackVolumeTests(OSIntegrationTestCase):
"""
- Tests for the CreateStack class as they pertain to volumes
+ Tests to ensure that floating IPs can be accessed via an
+ OpenStackVolume object obtained from the OpenStackHeatStack instance
"""
def setUp(self):
- """
- Instantiates the CreateStack object that is responsible for downloading
- and creating an OS stack file within OpenStack
- """
+
super(self.__class__, self).__start__()
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
class CreateStackFlavorTests(OSIntegrationTestCase):
"""
- Tests for the CreateStack class defined in create_stack.py
+ Tests to ensure that floating IPs can be accessed via an
+ OpenStackFlavor object obtained from the OpenStackHeatStack instance
"""
def setUp(self):
- """
- Instantiates the CreateStack object that is responsible for downloading
- and creating an OS stack file within OpenStack
- """
+
super(self.__class__, self).__start__()
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
class CreateStackKeypairTests(OSIntegrationTestCase):
"""
- Tests for the CreateStack class as they pertain to keypairs
+ Tests to ensure that floating IPs can be accessed via an
+ OpenStackKeypair object obtained from the OpenStackHeatStack instance
"""
def setUp(self):
- """
- Instantiates the CreateStack object that is responsible for downloading
- and creating an OS stack file within OpenStack
- """
+
super(self.__class__, self).__start__()
self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
class CreateStackNegativeTests(OSIntegrationTestCase):
"""
- Negative test cases for the CreateStack class
+ Negative test cases for the OpenStackHeatStack class with poor
+ configuration
"""
def setUp(self):
+
super(self.__class__, self).__start__()
self.heat_creds = self.admin_os_creds
stack_settings)
with self.assertRaises(IOError):
self.stack_creator.create()
+
+
+ class CreateStackFailureTests(OSIntegrationTestCase):
+ """
+ Tests for the OpenStackHeatStack class defined in create_stack.py for
+ when failures occur. Failures are being triggered by allocating 1 million
+ CPUs.
+ """
+
+ def setUp(self):
+
+ super(self.__class__, self).__start__()
+
+ self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
+
+ self.heat_creds = self.admin_os_creds
+ self.heat_creds.project_name = self.admin_os_creds.project_name
+
+ self.heat_cli = heat_utils.heat_client(self.heat_creds)
+ self.stack_creator = None
+
+ self.tmp_file = file_utils.save_string_to_file(
+ ' ', str(uuid.uuid4()) + '-bad-image')
+ self.image_creator = OpenStackImage(
+ self.heat_creds, ImageSettings(
+ name=self.guid + 'image', image_file=self.tmp_file.name,
+ image_user='foo', img_format='qcow2'))
+ self.image_creator.create()
+
+ # Create Flavor
+ self.flavor_creator = OpenStackFlavor(
+ self.admin_os_creds,
+ FlavorSettings(name=self.guid + '-flavor-name', ram=256, disk=10,
+ vcpus=1000000))
+ self.flavor_creator.create()
+
+ self.network_name = self.guid + '-net'
+ self.subnet_name = self.guid + '-subnet'
+ self.vm_inst_name = self.guid + '-inst'
+
+ self.env_values = {
+ 'image_name': self.image_creator.image_settings.name,
+ 'flavor_name': self.flavor_creator.flavor_settings.name,
+ 'net_name': self.network_name,
+ 'subnet_name': self.subnet_name,
+ 'inst_name': self.vm_inst_name}
+
+ self.heat_tmplt_path = pkg_resources.resource_filename(
+ 'snaps.openstack.tests.heat', 'test_heat_template.yaml')
+
+ def tearDown(self):
+ """
+ Cleans the stack and downloaded stack file
+ """
+ if self.stack_creator:
+ try:
+ self.stack_creator.clean()
+ except:
+ pass
+
+ if self.image_creator:
+ try:
+ self.image_creator.clean()
+ except:
+ pass
+
+ if self.flavor_creator:
+ try:
+ self.flavor_creator.clean()
+ except:
+ pass
+
+ if self.tmp_file:
+ try:
+ os.remove(self.tmp_file.name)
+ except:
+ pass
+
+ super(self.__class__, self).__clean__()
+
+ def test_stack_failure(self):
+ """
+ Tests the creation of an OpenStack stack from Heat template file that
+ should always fail due to too many CPU cores
+ """
+ # Create Stack
+ # Set the default stack settings, then set any custom parameters sent
+ # from the app
+ stack_settings = StackSettings(
+ name=self.__class__.__name__ + '-' + str(self.guid) + '-stack',
+ template_path=self.heat_tmplt_path,
+ env_values=self.env_values)
+ self.stack_creator = create_stack.OpenStackHeatStack(self.heat_creds,
+ stack_settings)
+
+ with self.assertRaises(StackError):
+ try:
+ self.stack_creator.create()
+ except StackError:
+ resources = heat_utils.get_resources(
+ self.heat_cli, self.stack_creator.get_stack())
+
+ found = False
+ for resource in resources:
+ if resource.status == create_stack.STATUS_CREATE_COMPLETE:
+ found = True
+ self.assertTrue(found)
+ raise