Пример #1
0
    def test_key_pair_exists_error_create(self):
        """ this tests that an error is raised if a
            keypair already exists in the file location
        """
        ctx = self.mock_ctx('test_key_pair_exists_error_create')
        current_ctx.set(ctx=ctx)

        key_path = self.create_dummy_key_path(ctx=ctx)
        keypair.create(ctx=ctx)
        self.addCleanup(os.remove, key_path)
        ex = self.assertRaises(NonRecoverableError, keypair.create, ctx=ctx)
        self.assertIn('already exists', ex.message)
    def test_key_pair_exists_error_create(self):
        """ this tests that an error is raised if a
            keypair already exists in the file location
        """
        ctx = self.mock_ctx('test_key_pair_exists_error_create')
        current_ctx.set(ctx=ctx)

        key_path = self.create_dummy_key_path(ctx=ctx)
        keypair.create(ctx=ctx)
        self.addCleanup(os.remove, key_path)
        ex = self.assertRaises(NonRecoverableError, keypair.create,
                               ctx=ctx)
        self.assertIn('already exists', ex.message)
    def test_create(self):
        """ This tests that the key pair name is added to the
        runtime_properties.
        """
        ctx = self.mock_ctx('test_create')
        current_ctx.set(ctx=ctx)

        key_path = self.create_dummy_key_path(ctx=ctx)
        keypair.create(ctx=ctx)
        self.addCleanup(os.remove, key_path)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
        self.assertTrue(os.path.exists(key_path))
Пример #4
0
    def test_create(self):
        """ This tests that the key pair name is added to the
        runtime_properties.
        """
        ctx = self.mock_ctx('test_create')
        current_ctx.set(ctx=ctx)

        key_path = self.create_dummy_key_path(ctx=ctx)
        keypair.create(ctx=ctx)
        self.addCleanup(os.remove, key_path)
        self.assertIn('aws_resource_id',
                      ctx.instance.runtime_properties.keys())
        self.assertTrue(os.path.exists(key_path))
Пример #5
0
 def test_delete_different_resource_id_and_file_path(self):
     """ This makes sure that delete deletes when the resource_id and
     the private_key_path differ.
     """
     temp_key = tempfile.mktemp()
     ctx = self.mock_ctx('test_delete_different_resource_id_and_file_path')
     ctx.node.properties['private_key_path'] = temp_key
     ctx.node.properties['resource_id'] = 'something_else'
     current_ctx.set(ctx=ctx)
     keypair.create(ctx=ctx)
     self.assertTrue(os.path.exists(temp_key))
     keypair.delete(ctx=ctx)
     self.assertFalse(os.path.exists(temp_key))
Пример #6
0
    def test_runtime_property_deleted(self):
        """ This tests that the key pair type is added to and removed from the
        runtime_properties.
        """
        ctx = self.mock_ctx('test_key_pair_type')
        current_ctx.set(ctx=ctx)

        keypair.create(ctx=ctx)
        self.assertIn('external_type', ctx.instance.runtime_properties.keys())
        self.assertEqual('keypair',
                         ctx.instance.runtime_properties['external_type'])

        keypair.delete(ctx=ctx)
        self.assertNotIn('external_type',
                         ctx.instance.runtime_properties.keys())
 def test_delete_different_resource_id_and_file_path(self):
     """ This makes sure that delete deletes when the resource_id and
     the private_key_path differ.
     """
     temp_key = tempfile.mktemp()
     ctx = self.mock_ctx(
         'test_delete_different_resource_id_and_file_path')
     ctx.node.properties['private_key_path'] = temp_key
     ctx.node.properties['resource_id'] = 'something_else'
     current_ctx.set(ctx=ctx)
     keypair.create(ctx=ctx)
     self.assertTrue(
         os.path.exists(temp_key))
     keypair.delete(ctx=ctx)
     self.assertFalse(
         os.path.exists(temp_key))
    def test_runtime_property_deleted(self):
        """ This tests that the key pair type is added to and removed from the
        runtime_properties.
        """
        ctx = self.mock_ctx('test_key_pair_type')
        current_ctx.set(ctx=ctx)

        keypair.create(ctx=ctx)
        self.assertIn('external_type',
                      ctx.instance.runtime_properties.keys())
        self.assertEqual('keypair',
                         ctx.instance.runtime_properties['external_type'])

        keypair.delete(ctx=ctx)
        self.assertNotIn('external_type',
                         ctx.instance.runtime_properties.keys())
    def test_file_already_exists(self):
        """Tests that if a file already exists at
        private_key_path, then an error is raised.
        """

        temp_key = tempfile.mktemp()
        self.addCleanup(os.remove, temp_key)
        with open(temp_key, 'w') as outfile:
            outfile.write('')
        ctx = self.mock_ctx('test_file_already_exists')
        ctx.node.properties['private_key_path'] = temp_key
        ctx.node.properties['resource_id'] = 'something_else'
        current_ctx.set(ctx=ctx)
        with self.assertRaisesRegexp(
                NonRecoverableError,
                '{0} already exists, it will not be overwritten'.format(
                    temp_key)):
            keypair.create(ctx=ctx)
Пример #10
0
    def test_file_already_exists(self):
        """Tests that if a file already exists at
        private_key_path, then an error is raised.
        """

        temp_key = tempfile.mktemp()
        self.addCleanup(os.remove, temp_key)
        with open(temp_key, 'w') as outfile:
            outfile.write('')
        ctx = self.mock_ctx('test_file_already_exists')
        ctx.node.properties['private_key_path'] = temp_key
        ctx.node.properties['resource_id'] = 'something_else'
        current_ctx.set(ctx=ctx)
        with self.assertRaisesRegexp(
                NonRecoverableError,
                '{0} already exists, it will not be overwritten'.format(
                    temp_key)):
            keypair.create(ctx=ctx)