diff options
-rw-r--r-- | snaps/openstack/create_keypairs.py | 2 | ||||
-rw-r--r-- | snaps/openstack/tests/create_stack_tests.py | 47 | ||||
-rw-r--r-- | snaps/openstack/utils/tests/heat_utils_tests.py | 29 |
3 files changed, 60 insertions, 18 deletions
diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py index 3869afc..6c66134 100644 --- a/snaps/openstack/create_keypairs.py +++ b/snaps/openstack/create_keypairs.py @@ -123,6 +123,7 @@ class OpenStackKeypair(OpenStackComputeObject): self.keypair_settings.public_filepath) os.chmod(expanded_path, 0o755) os.remove(expanded_path) + logger.info('Deleted public key file [%s]', expanded_path) if (self.keypair_settings.private_filepath and file_utils.file_exists( self.keypair_settings.private_filepath)): @@ -130,6 +131,7 @@ class OpenStackKeypair(OpenStackComputeObject): self.keypair_settings.private_filepath) os.chmod(expanded_path, 0o755) os.remove(expanded_path) + logger.info('Deleted private key file [%s]', expanded_path) def get_keypair(self): """ diff --git a/snaps/openstack/tests/create_stack_tests.py b/snaps/openstack/tests/create_stack_tests.py index dbe5e3a..9a26918 100644 --- a/snaps/openstack/tests/create_stack_tests.py +++ b/snaps/openstack/tests/create_stack_tests.py @@ -441,6 +441,8 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): self.heat_tmplt_path = pkg_resources.resource_filename( 'snaps.openstack.tests.heat', 'floating_ip_heat_template.yaml') + self.vm_inst_creators = list() + def tearDown(self): """ Cleans the stack and downloaded stack file @@ -457,6 +459,17 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): except: pass + for vm_inst_creator in self.vm_inst_creators: + try: + keypair_settings = vm_inst_creator.keypair_settings + if keypair_settings and keypair_settings.private_filepath: + expanded_path = os.path.expanduser( + keypair_settings.private_filepath) + os.chmod(expanded_path, 0o755) + os.remove(expanded_path) + except: + pass + super(self.__class__, self).__clean__() def test_connect_via_ssh_heat_vm(self): @@ -475,12 +488,12 @@ class CreateStackFloatingIpTests(OSIntegrationTestCase): created_stack = self.stack_creator.create() self.assertIsNotNone(created_stack) - vm_inst_creators = self.stack_creator.get_vm_inst_creators( + self.vm_inst_creators = self.stack_creator.get_vm_inst_creators( heat_keypair_option='private_key') - self.assertIsNotNone(vm_inst_creators) - self.assertEqual(2, len(vm_inst_creators)) + self.assertIsNotNone(self.vm_inst_creators) + self.assertEqual(2, len(self.vm_inst_creators)) - for vm_inst_creator in vm_inst_creators: + for vm_inst_creator in self.vm_inst_creators: if vm_inst_creator.get_vm_inst().name == self.vm_inst1_name: self.assertTrue( create_instance_tests.validate_ssh_client(vm_inst_creator)) @@ -753,6 +766,8 @@ class CreateStackKeypairTests(OSIntegrationTestCase): self.created_stack = self.stack_creator.create() self.assertIsNotNone(self.created_stack) + self.keypair_creators = list() + def tearDown(self): """ Cleans the stack and downloaded stack file @@ -762,6 +777,11 @@ class CreateStackKeypairTests(OSIntegrationTestCase): self.stack_creator.clean() except: pass + for keypair_creator in self.keypair_creators: + try: + keypair_creator.clean() + except: + pass super(self.__class__, self).__clean__() @@ -770,23 +790,26 @@ class CreateStackKeypairTests(OSIntegrationTestCase): Tests the creation of an OpenStack stack from Heat template file and the retrieval of an OpenStackKeypair creator/state machine instance """ - kp_creators = self.stack_creator.get_keypair_creators('private_key') - self.assertEqual(1, len(kp_creators)) + self.kp_creators = self.stack_creator.get_keypair_creators( + 'private_key') + self.assertEqual(1, len(self.kp_creators)) - creator = kp_creators[0] + self.keypair_creator = self.kp_creators[0] - self.assertEqual(self.keypair_name, creator.get_keypair().name) - self.assertIsNotNone(creator.keypair_settings.private_filepath) + self.assertEqual(self.keypair_name, + self.keypair_creator.get_keypair().name) + self.assertIsNotNone( + self.keypair_creator.keypair_settings.private_filepath) private_file_contents = file_utils.read_file( - creator.keypair_settings.private_filepath) + self.keypair_creator.keypair_settings.private_filepath) self.assertTrue(private_file_contents.startswith( '-----BEGIN RSA PRIVATE KEY-----')) keypair = nova_utils.get_keypair_by_id( - self.nova, creator.get_keypair().id) + self.nova, self.keypair_creator.get_keypair().id) self.assertIsNotNone(keypair) - self.assertEqual(creator.get_keypair(), keypair) + self.assertEqual(self.keypair_creator.get_keypair(), keypair) class CreateStackSecurityGroupTests(OSIntegrationTestCase): diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py index 4373b8a..1068903 100644 --- a/snaps/openstack/utils/tests/heat_utils_tests.py +++ b/snaps/openstack/utils/tests/heat_utils_tests.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import os + import pkg_resources import uuid @@ -277,6 +279,9 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): self.assertTrue(stack_active(self.heat_client, self.stack)) + self.keypair1_settings = None + self.keypair2_settings = None + def tearDown(self): """ Cleans the stack and image @@ -335,6 +340,18 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): except: pass + if self.keypair1_settings: + expanded_path = os.path.expanduser( + self.keypair1_settings.private_filepath) + os.chmod(expanded_path, 0o755) + os.remove(expanded_path) + + if self.keypair2_settings: + expanded_path = os.path.expanduser( + self.keypair2_settings.private_filepath) + os.chmod(expanded_path, 0o755) + os.remove(expanded_path) + def test_get_settings_from_stack(self): """ Tests that a heat template with floating IPs and can have the proper @@ -392,17 +409,17 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): self.assertEqual( self.image_creator2.image_settings.name, image_settings.name) - keypair1_settings = settings_utils.determine_keypair_settings( + self.keypair1_settings = settings_utils.determine_keypair_settings( self.heat_client, self.stack, servers[0], priv_key_key='private_key') - self.assertIsNotNone(keypair1_settings) - self.assertEqual(self.keypair_name, keypair1_settings.name) + self.assertIsNotNone(self.keypair1_settings) + self.assertEqual(self.keypair_name, self.keypair1_settings.name) - keypair2_settings = settings_utils.determine_keypair_settings( + self.keypair2_settings = settings_utils.determine_keypair_settings( self.heat_client, self.stack, servers[1], priv_key_key='private_key') - self.assertIsNotNone(keypair2_settings) - self.assertEqual(self.keypair_name, keypair2_settings.name) + self.assertIsNotNone(self.keypair2_settings) + self.assertEqual(self.keypair_name, self.keypair2_settings.name) class HeatUtilsRouterTests(OSComponentTestCase): |