コード例 #1
0
    def test_get_by_name(self, mock_client):
        mock_client.return_value.describe_connections.return_value = {
            "connections": [
                {
                    "connectionState": "requested",
                    "connectionId": "dxcon-fgq9rgot",
                    "location": "EqSe2",
                    "connectionName": "ansible-test-connection",
                    "bandwidth": "1Gbps",
                    "ownerAccount": "448830907657",
                    "region": "us-west-2"
                }
            ]
        }
        set_module_args({
            "name": "ansible-test-connection"
        })
        with self.assertRaises(AnsibleExitJson) as exec_info:
            aws_direct_connect_confirm_connection.main()

        result = exec_info.exception.args[0]
        assert result["changed"] is False
        assert result["connection_state"] == "requested"
        mock_client.return_value.describe_connections.assert_has_calls([
            call(),
            call(connectionId="dxcon-fgq9rgot")
        ])
        mock_client.return_value.confirm_connection.assert_not_called()
コード例 #2
0
    def test_confirm(self, mock_client):
        mock_client.return_value.describe_connections.return_value = {
            "connections": [{
                "connectionState": "ordering",
                "connectionId": "dxcon-fgq9rgot",
                "location": "EqSe2",
                "connectionName": "ansible-test-connection",
                "bandwidth": "1Gbps",
                "ownerAccount": "448830907657",
                "region": "us-west-2"
            }]
        }
        mock_client.return_value.confirm_connection.return_value = [{}]
        set_module_args({"connection_id": "dxcon-fgq9rgot"})
        with self.assertRaises(AnsibleExitJson) as exec_info:
            aws_direct_connect_confirm_connection.main()

        result = exec_info.exception.args[0]
        assert result["changed"] is True
        mock_client.return_value.describe_connections.assert_has_calls([
            call(connectionId="dxcon-fgq9rgot"),
            call(connectionId="dxcon-fgq9rgot"),
            call(connectionId="dxcon-fgq9rgot")
        ])
        mock_client.return_value.confirm_connection.assert_called_once_with(
            connectionId="dxcon-fgq9rgot")
コード例 #3
0
    def test_missing_name(self, mock_client):
        mock_client.return_value.describe_connections.return_value = {
            "connections": [
                {
                    "connectionState": "requested",
                    "connectionId": "dxcon-fgq9rgot",
                    "location": "EqSe2",
                    "connectionName": "ansible-test-connection",
                    "bandwidth": "1Gbps",
                    "ownerAccount": "448830907657",
                    "region": "us-west-2"
                }
            ]
        }
        set_module_args({
            "name": "foobar"
        })
        with self.assertRaises(AnsibleFailJson) as exec_info:
            aws_direct_connect_confirm_connection.main()

        result = exec_info.exception.args[0]
        assert result["failed"] is True
        mock_client.return_value.describe_connections.assert_has_calls([
            call()
        ])
コード例 #4
0
    def test_missing_required_parameters(self, *args):
        set_module_args({})
        with self.assertRaises(AnsibleFailJson) as exec_info:
            aws_direct_connect_confirm_connection.main()

        result = exec_info.exception.args[0]
        assert result["failed"] is True
        assert "name" in result["msg"]
        assert "connection_id" in result["msg"]
コード例 #5
0
    def test_missing_connection_id(self, mock_client):
        mock_client.return_value.describe_connections.side_effect = ClientError(
            {'Error': {
                'Code': 'ResourceNotFoundException'
            }}, 'DescribeConnection')
        set_module_args({"connection_id": "dxcon-aaaabbbb"})
        with self.assertRaises(AnsibleFailJson) as exec_info:
            aws_direct_connect_confirm_connection.main()

        result = exec_info.exception.args[0]
        assert result["failed"] is True
        mock_client.return_value.describe_connections.assert_has_calls(
            [call(connectionId="dxcon-aaaabbbb")])