def test_bootstrap_context_key_pair(self, *_):
        """tests finding a key file via bootstrap context
        """

        name = 'test_bootstrap_context_key_pair'
        private_key_dir = tempfile.mkdtemp()
        private_key_path = '{0}/{1}.pem' \
            .format(private_key_dir, name)
        open(private_key_path, 'w').close()

        cloudify_agent = MockContext()
        cloudify_agent['agent_key_path'] = private_key_path

        bootstrap_ctx = BootstrapContext({
            'cloudify_agent': cloudify_agent
        })

        ctx = MockCloudifyContext(bootstrap_context=bootstrap_ctx,
                                  node_name=name)
        current_ctx.set(ctx=ctx)

        with mock.patch('ec2.utils.get_single_connected_node_by_type') \
                as mock_get_connected:
            mock_get_connected.return_value = None
            output = instance._get_private_key('')
            self.assertEqual(private_key_path, output)
    def test_relationship_key_pair(self, *_):
        """tests finding a key file via relationship
        """

        name = 'test_relationship_key_pair'
        ctx = self.mock_ctx(name)
        current_ctx.set(ctx=ctx)

        ctx.node.properties['use_password'] = True
        private_key_dir = tempfile.mkdtemp()
        private_key_path = '{0}/{1}.pem' \
            .format(private_key_dir, name)
        open(private_key_path, 'w').close()

        key_pair_node = MockNodeContext(
            properties={'private_key_path': private_key_path})

        with mock.patch('ec2.utils.get_single_connected_node_by_type') \
                as mock_get_single_connected_node_by_type:
            mock_get_single_connected_node_by_type.return_value = key_pair_node
            output = instance._get_private_key('')
            self.assertEqual(private_key_path, output)
    def test_relationship_key_pair(self, *_):
        """tests finding a key file via relationship
        """

        name = 'test_relationship_key_pair'
        ctx = self.mock_ctx(name)
        current_ctx.set(ctx=ctx)

        ctx.node.properties['use_password'] = True
        private_key_dir = tempfile.mkdtemp()
        private_key_path = '{0}/{1}.pem' \
            .format(private_key_dir, name)
        open(private_key_path, 'w').close()

        key_pair_node = MockNodeContext(properties={
            'private_key_path': private_key_path
        })

        with mock.patch('ec2.utils.get_single_connected_node_by_type') \
                as mock_get_single_connected_node_by_type:
            mock_get_single_connected_node_by_type.return_value = key_pair_node
            output = instance._get_private_key('')
            self.assertEqual(private_key_path, output)
    def test_bootstrap_context_key_pair(self, *_):
        """tests finding a key file via bootstrap context
        """

        name = 'test_bootstrap_context_key_pair'
        private_key_dir = tempfile.mkdtemp()
        private_key_path = '{0}/{1}.pem' \
            .format(private_key_dir, name)
        open(private_key_path, 'w').close()

        cloudify_agent = MockContext()
        cloudify_agent['agent_key_path'] = private_key_path

        bootstrap_ctx = BootstrapContext({'cloudify_agent': cloudify_agent})

        ctx = MockCloudifyContext(bootstrap_context=bootstrap_ctx,
                                  node_name=name)
        current_ctx.set(ctx=ctx)

        with mock.patch('ec2.utils.get_single_connected_node_by_type') \
                as mock_get_connected:
            mock_get_connected.return_value = None
            output = instance._get_private_key('')
            self.assertEqual(private_key_path, output)