def test_import_keypair(self):
        data = self.get_example_data()
        data['Action'] = 'ImportKeyPair'
        data['KeyName'] = 'Test'
        data['PublicKeyMaterial'] = b64encode(
            'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCaqPfl99phOoszUD6n9xNKUtjqof'
            'hktvGxuhT2BgiTNi55FNfHAPyXyakQ86NbZPEQoRiDGyOI6BQVOmd+811Z+tFpB8Es'
            'Y9t7tFAohid6G6bn7/Z78beXXMk9lcc7bnCVZaeZmAjHSTBHinlcWqB3P5IPJTASVe'
            'ktX8drPXXyTCEp5NlJdSTmfnQJAm9Ho5YMlHGAMyW8aIBKBrpwjx6RAYnPcIWm0Jsv'
            'oSrPTeM9koziSRBROG06UT3FSslwuetcQvHsvIPHJ1IrwHljXQomOf7GLgSzbp6Czv'
            'lY6Leh9OQOcv70dYy5RcoEoVh+Lta5LpyiUL/ntW270M29lxpB'
        )
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_import_keypair.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'ImportKeyPairResponse' in response.data
Exemple #2
0
    def test_create_volume_invalid_snapshot(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['SnapshotId'] = 'invalid-snapshot-id'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get_request = mock.Mock()
        get_request.return_value.text = read_file(
            'tests/data/create_volume_invalid_snapshot_response.json'
        )
        get_request.return_value.status_code = 431

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get_request):
            with mock.patch(
                    'ec2stack.providers.cloudstack.zones.get_zone',
                    get_zone
            ):
                response = self.post(
                    '/',
                    data=data
                )

        self.assert_bad_request(response)
        assert 'InvalidSnapshot.NotFound' in response.data
Exemple #3
0
    def test_create_volume_by_snapshot(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['SnapshotId'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/create_volume_response.json'
        )
        get.return_value.status_code = 200

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.zones.get_zone',
                    get_zone
            ):
                response = self.post(
                    '/',
                    data=data
                )

        self.assert_ok(response)
        assert 'CreateVolumeResponse' in response.data
    def test_invalid_security_group_authorize_security_group(self):
        data = self.get_example_data()
        data['Action'] = 'AuthorizeSecurityGroupEgress'
        data['GroupName'] = 'invalid-security-group'
        data['FromPort'] = '1000'
        data['ToPort'] = '1024'
        data['IpProtocol'] = 'tcp'
        data['CidrIp'] = '0.0.0.0/24'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/'
            'invalid_security_group_authorize_security_group.json'
        )
        get.return_value.status_code = 431

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidGroup.NotFound' in response.data
Exemple #5
0
    def test_run_instance_unknown_issue(self):
        data = self.get_example_data()
        data["Action"] = "RunInstances"
        data["ImageId"] = "a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d"
        data["MinCount"] = "0"
        data["MaxCount"] = "0"
        data["SecurityGroupId.1"] = "example-security-group-id"
        data["SecurityGroup.1"] = "example-security-group-name"
        data["KeyName"] = "example-ssh-key-name"
        data["UserData"] = "example-user-data"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/invalid_run_instance_unknown_issue.json")
        get.return_value.status_code = 431

        get_service_offering = mock.Mock()
        get_service_offering.return_value = json.loads(read_file("tests/data/service_offering_search.json"))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file("tests/data/zones_search.json"))

        with mock.patch("requests.get", get):
            with mock.patch(
                "ec2stack.providers.cloudstack.service_offerings.get_service_offering", get_service_offering
            ):
                with mock.patch("ec2stack.providers.cloudstack.zones.get_zone", get_zone):
                    response = self.post("/", data=data)

        self.assert_bad_request(response)
        assert "InvalidRequest" in response.data
    def test_invalid_revoke_security_group(self):
        data = self.get_example_data()
        data['Action'] = 'RevokeSecurityGroupEgress'
        data['GroupId'] = '7ae5b92f-3a0d-4977-bc33-f1aaecee5776'
        data['FromPort'] = '0'
        data['ToPort'] = '0'
        data['IpProtocol'] = 'invalid'
        data['CidrIp'] = '192.168.0.0/24'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/revoke_security_group_egress.json'
        )
        get.return_value.status_code = 200

        describe_item_request = mock.Mock()
        describe_item_request.return_value = json.loads(read_file(
            'tests/data/revoke_security_group_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.describe_item_request',
                    describe_item_request
            ):
                response = self.post(
                    '/',
                    data=data
                )

        self.assert_bad_request(response)
        assert 'InvalidPermission.NotFound' in response.data
    def test_create_vpc_invalid_cidr(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVpc'
        data['CidrBlock'] = '192.168.0.0/33'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_create_vpc_invalid_cidr.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            with mock.patch(
                'ec2stack.providers.cloudstack.zones.get_zone',
                get_zone
            ):
                response = self.post(
                    '/',
                    data=data
                )

        self.assert_bad_request(response)
        assert 'InvalidVpcRange' in response.data
    def test_terminate_instance(self):
        data = self.get_example_data()
        data['Action'] = 'TerminateInstances'
        data['InstanceId.1'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_terminate_instance.json'
        )
        get.return_value.status_code = 200

        get_instance = mock.Mock()
        get_instance.return_value = json.loads(read_file(
            'tests/data/valid_get_instance_by_id.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.instances.describe_instance_by_id',
                    get_instance
            ):
                response = self.post(
                    '/',
                    data=data
                )

        self.assert_ok(response)
        assert 'TerminateInstancesResponse' in response.data
    def test_run_instance_gp2(self):
        data = self.get_example_data()
        data['Action'] = 'RunInstances'
        data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
        data['MinCount'] = '0'
        data['MaxCount'] = '0'
        data['SecurityGroupId.1'] = 'example-security-group-id'
        data['SecurityGroup.1'] = 'example-security-group-name'
        data['KeyName'] = 'example-ssh-key-name'
        data['UserData'] = 'example-user-data'
        data['BlockDeviceMapping.1.Ebs.VolumeType'] = 'gp2'
        data['BlockDeviceMapping.1.Ebs.VolumeSize'] = '20'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_run_instance.json'
        )
        get.return_value.status_code = 200

        get_disk_offering = mock.Mock()
        get_disk_offering.return_value = json.loads(read_file(
            'tests/data/disk_offering_search.json'
        ))

        get_service_offering = mock.Mock()
        get_service_offering.return_value = json.loads(read_file(
            'tests/data/service_offering_search.json'
        ))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering',
                    get_disk_offering
            ):
                with mock.patch(
                        'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
                        get_service_offering
                ):
                    with mock.patch(
                            'ec2stack.providers.cloudstack.zones.get_zone',
                            get_zone
                    ):
                        response = self.post(
                            '/',
                            data=data
                        )

        self.assert_ok(response)
        assert 'RunInstancesResponse' in response.data
    def test_invalid_delete_security_group(self):
        data = self.get_example_data()
        data['Action'] = 'DeleteSecurityGroup'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        response = self.post(
            '/',
            data=data
        )

        self.assert_bad_request(response)
        assert 'MissingParameter' in response.data
Exemple #11
0
    def test_bad_request_on_provider_error(self):
        data = self.get_example_data()
        data['Action'] = 'CreateKeyPair'
        data['KeyName'] = 'Test'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.status_code = 401

        with mock.patch('requests.get', get):
            response = self.post('/', data=data)

        self.assert_bad_request(response)
Exemple #12
0
    def test_empty_response_describe_instances(self):
        data = self.get_example_data()
        data["Action"] = "DescribeInstances"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/empty_describe_instances.json")
        get.return_value.status_code = 200

        with mock.patch("requests.get", get):
            response = self.post("/", data=data)

        self.assert_ok(response)
        assert "DescribeInstancesResponse" in response.data
Exemple #13
0
    def test_invalid_describe_instance_by_id(self):
        data = self.get_example_data()
        data["Action"] = "DescribeInstances"
        data["InstanceId.1"] = "invalid-instance-id"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/valid_describe_instances.json")
        get.return_value.status_code = 200

        with mock.patch("requests.get", get):
            response = self.post("/", data=data)

        self.assert_bad_request(response)
        assert "InvalidInstanceId.NotFound" in response.data
Exemple #14
0
    def test_reboot_instance(self):
        data = self.get_example_data()
        data["Action"] = "RebootInstances"
        data["InstanceId.1"] = "076166a1-9f6e-11e3-b8df-3c075456b21a"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/valid_reboot_instance.json")
        get.return_value.status_code = 200

        with mock.patch("requests.get", get):
            response = self.post("/", data=data)

        self.assert_ok(response)
        assert "RebootInstancesResponse" in response.data
Exemple #15
0
    def test_describe_instance_by_id(self):
        data = self.get_example_data()
        data["Action"] = "DescribeInstances"
        data["InstanceId.1"] = "aa10a43e-56db-4a34-88bd-1c2a51c0bc04"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/valid_describe_instances.json")
        get.return_value.status_code = 200

        with mock.patch("requests.get", get):
            response = self.post("/", data=data)

        self.assert_ok(response)
        assert "DescribeInstancesResponse" in response.data
        assert "aa10a43e-56db-4a34-88bd-1c2a51c0bc04" in response.data
Exemple #16
0
    def test_describe_invalid_instance_attribute(self):
        data = self.get_example_data()
        data["Action"] = "DescribeInstanceAttribute"
        data["InstanceId"] = "43791f77-26f8-48ca-b557-3a9392f735ae"
        data["Attribute"] = "invalid_attribute"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/valid_describe_instance.json")
        get.return_value.status_code = 200

        with mock.patch("requests.get", get):
            response = self.post("/", data=data)

        self.assert_bad_request(response)
        assert "InvalidParameterValue" in response.data
    def test_get_service_offering_invalid_name(self):
        data = self.get_example_data()
        data['Action'] = 'RunInstances'
        data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
        data['InstanceType'] = 'invalid-instance-type'
        data['MinCount'] = '0'
        data['MaxCount'] = '0'
        data['SecurityGroupId.1'] = 'example-security-group-id'
        data['SecurityGroup.1'] = 'example-security-group-name'
        data['KeyName'] = 'example-ssh-key-name'
        data['UserData'] = 'example-user-data'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_run_instance.json'
        )
        get.return_value.status_code = 200

        get_service_offering = mock.Mock()
        get_service_offering.return_value = json.loads(read_file(
            'tests/data/service_offerings_search.json'
        ))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.describe_items_request',
                    get_service_offering
            ):
                with mock.patch(
                        'ec2stack.providers.cloudstack.zones.get_zone',
                        get_zone
                ):
                    response = self.post(
                        '/',
                        data=data
                    )

        self.assert_bad_request(response)
        assert 'InvalidServiceOffering.NotFound' in response.data
    def test_run_instance_invalid_image_id(self):
        data = self.get_example_data()
        data['Action'] = 'RunInstances'
        data['ImageId'] = 'invalid-id'
        data['MinCount'] = '0'
        data['MaxCount'] = '0'
        data['SecurityGroupId.1'] = 'example-security-group-id'
        data['SecurityGroup.1'] = 'example-security-group-name'
        data['KeyName'] = 'example-ssh-key-name'
        data['UserData'] = 'example-user-data'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_run_instance_image_not_found.json'
        )
        get.return_value.status_code = 431

        get_service_offering = mock.Mock()
        get_service_offering.return_value = json.loads(read_file(
            'tests/data/service_offering_search.json'
        ))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
                    get_service_offering
            ):
                with mock.patch(
                        'ec2stack.providers.cloudstack.zones.get_zone',
                        get_zone
                ):
                    response = self.post(
                        '/',
                        data=data
                    )

        self.assert_bad_request(response)
        assert 'InvalidAMIID.NotFound' in response.data
Exemple #19
0
    def test_terminate_instance(self):
        data = self.get_example_data()
        data["Action"] = "TerminateInstances"
        data["InstanceId.1"] = "076166a1-9f6e-11e3-b8df-3c075456b21a"
        data["Signature"] = generate_signature(data, "POST", "localhost", "/")

        get = mock.Mock()
        get.return_value.text = read_file("tests/data/valid_terminate_instance.json")
        get.return_value.status_code = 200

        get_instance = mock.Mock()
        get_instance.return_value = json.loads(read_file("tests/data/valid_get_instance_by_id.json"))

        with mock.patch("requests.get", get):
            with mock.patch("ec2stack.providers.cloudstack.instances.describe_instance_by_id", get_instance):
                response = self.post("/", data=data)

        self.assert_ok(response)
        assert "TerminateInstancesResponse" in response.data
Exemple #20
0
    def test_describe_tags(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeTags'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_describe_tags.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'DescribeTagsResponse' in response.data
Exemple #21
0
    def test_delete_volume_invalid_volume_id(self):
        data = self.get_example_data()
        data['Action'] = 'DeleteVolume'
        data['VolumeId'] = 'volumeid'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get_request = mock.Mock()
        get_request.return_value.text = read_file(
            'tests/data/invalid_delete_volume_invalid_volume_id.json'
        )
        get_request.return_value.status_code = 200

        with mock.patch('requests.get', get_request):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.NotFound' in response.data
    def test_reboot_instance(self):
        data = self.get_example_data()
        data['Action'] = 'RebootInstances'
        data['InstanceId.1'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_reboot_instance.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'RebootInstancesResponse' in response.data
Exemple #23
0
    def test_invalid_describe_zone_by_name(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeAvailabilityZones'
        data['ZoneName.1'] = 'invalid-zone-name'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_describe_zone.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidZone.NotFound' in response.data
    def test_duplicate_keypair(self):
        data = self.get_example_data()
        data['Action'] = 'CreateKeyPair'
        data['KeyName'] = 'Test'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_create_keypair_duplicate.json'
        )
        get.return_value.status_code = 431

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidKeyPair.Duplicate' in response.data
Exemple #25
0
    def test_detach_volume_volume_not_found(self):
        data = self.get_example_data()
        data['Action'] = 'DetachVolume'
        data['VolumeId'] = '0896ccff-1b7a-4c17-8390-02a602de2efe'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_detach_volume_volume_not_found.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.NotFound' in response.data
Exemple #26
0
    def test_delete_volume(self):
        data = self.get_example_data()
        data['Action'] = 'DeleteVolume'
        data['VolumeId'] = 'volumeid'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get_request = mock.Mock()
        get_request.return_value.text = read_file(
            'tests/data/delete_volume_response.json'
        )
        get_request.return_value.status_code = 200

        with mock.patch('requests.get', get_request):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'DeleteVolumeResponse' in response.data
    def test_delete_security_group_by_id(self):
        data = self.get_example_data()
        data['Action'] = 'DeleteSecurityGroup'
        data['GroupId'] = 'securitygroupname'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_delete_security_group.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'DeleteSecurityGroupResponse' in response.data
Exemple #28
0
    def test_detach_volume_volume_not_found(self):
        data = self.get_example_data()
        data['Action'] = 'DetachVolume'
        data['VolumeId'] = '0896ccff-1b7a-4c17-8390-02a602de2efe'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_detach_volume_volume_not_found.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.NotFound' in response.data
Exemple #29
0
    def test_empty_response_describe_volume_by_id(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeVolumes'
        data['VolumeId.1'] = 'invalid-volume-id'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/empty_describe_volumes.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.NotFound' in response.data
    def test_create_keypair(self):
        data = self.get_example_data()
        data['Action'] = 'CreateKeyPair'
        data['KeyName'] = 'Test'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_create_keypair.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'CreateKeyPairResponse' in response.data
    def test_describe_vpc_by_name_invalid_name(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeVpcs'
        data['VpcId'] = 'invalidevpc'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_describe_vpc.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVpcID.NotFound' in response.data
    def test_invalid_describe_key_pair_by_name(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeKeyPairs'
        data['KeyName'] = 'invalid-key-name'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_describe_key_pairs.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidKeyPair.NotFound' in response.data
    def test_invalid_get_password(self):
        data = self.get_example_data()
        data['Action'] = 'GetPasswordData'
        data['InstanceId'] = 'Test'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_instance_get_password.json'
        )
        get.return_value.status_code = 431

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidInstanceId.NotFound' in response.data
    def test_empty_response_describe_security_group_by_name(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeSecurityGroups'
        data['GroupName'] = 'invalid-name'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/empty_describe_security_groups.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidGroup.NotFound' in response.data
Exemple #35
0
    def test_empty_response_describe_volume_by_id(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeVolumes'
        data['VolumeId.1'] = 'invalid-volume-id'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/empty_describe_volumes.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.NotFound' in response.data
Exemple #36
0
    def test_invalid_security_group_authorize_security_group(self):
        data = self.get_example_data()
        data['Action'] = 'AuthorizeSecurityGroupEgress'
        data['GroupName'] = 'invalid-security-group'
        data['FromPort'] = '1000'
        data['ToPort'] = '1024'
        data['IpProtocol'] = 'tcp'
        data['CidrIp'] = '0.0.0.0/24'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/'
            'invalid_security_group_authorize_security_group.json')
        get.return_value.status_code = 431

        with mock.patch('requests.get', get):
            response = self.post('/', data=data)

        self.assert_bad_request(response)
        assert 'InvalidGroup.NotFound' in response.data
Exemple #37
0
    def test_detach_volume_with_virtualmachine(self):
        data = self.get_example_data()
        data['Action'] = 'DetachVolume'
        data['VolumeId'] = '0896ccff-1b7a-4c17-8390-02a602de2efe'
        data['InstanceId'] = 'ba918d10-f83a-459d-a5b9-330793c3c6a3'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_detach_volume.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'DetachVolumeResponse' in response.data
Exemple #38
0
    def test_create_volume_invalid_zone(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['SnapshotId'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/empty_describe_zone.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidZone.NotFound' in response.data
Exemple #39
0
    def test_describe_volume_by_id(self):
        data = self.get_example_data()
        data['Action'] = 'DescribeVolumes'
        data['VolumeId.1'] = 'de2d8297-eaaf-4e81-8ffe-97f37ddbbde5'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_describe_volumes.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_ok(response)
        assert 'DescribeVolumesResponse' in response.data
        assert 'de2d8297-eaaf-4e81-8ffe-97f37ddbbde5' in response.data
    def test_create_vpc(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVpc'
        data['CidrBlock'] = '192.168.0.0/24'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(
            read_file('tests/data/zones_search.json'))

        get = mock.Mock()
        get.return_value.text = read_file('tests/data/valid_create_vpc.json')
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            with mock.patch('ec2stack.providers.cloudstack.zones.get_zone',
                            get_zone):
                response = self.post('/', data=data)

        self.assert_ok(response)
        assert 'CreateVpcResponse' in response.data
Exemple #41
0
    def test_get_disk_offering(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['Size'] = '80'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_create_volume.json'
        )
        get.return_value.status_code = 200

        describe_disk_offering = mock.Mock()
        describe_disk_offering.return_value = json.loads(read_file(
            'tests/data/disk_offering_search.json'
        ))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(read_file(
            'tests/data/zones_search.json'
        ))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.describe_item_request',
                    describe_disk_offering
            ):
                with mock.patch(
                        'ec2stack.providers.cloudstack.zones.get_zone',
                        get_zone
                ):
                    response = self.post(
                        '/',
                        data=data
                    )

        self.assert_ok(response)
        assert 'CreateVolumeResponse' in response.data
Exemple #42
0
    def test_attach_volume_invalid_volume(self):
        data = self.get_example_data()
        data['Action'] = 'AttachVolume'
        data['VolumeId'] = '0896ccff-1b7a-4c17-8390-02a602de2efe'
        data['InstanceId'] = 'ba918d10-f83a-459d-a5b9-330793c3c6a3'
        data['Device'] = '/dev/sha'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/invalid_attach_volume_volume_attached.json'
        )
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            response = self.post(
                '/',
                data=data
            )

        self.assert_bad_request(response)
        assert 'InvalidVolume.Attached' in response.data
    def test_terminate_instance(self):
        data = self.get_example_data()
        data['Action'] = 'TerminateInstances'
        data['InstanceId.1'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_terminate_instance.json')
        get.return_value.status_code = 200

        get_instance = mock.Mock()
        get_instance.return_value = json.loads(
            read_file('tests/data/valid_get_instance_by_id.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.instances.describe_instance_by_id',
                    get_instance):
                response = self.post('/', data=data)

        self.assert_ok(response)
        assert 'TerminateInstancesResponse' in response.data
Exemple #44
0
    def test_create_volume_by_snapshot(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['SnapshotId'] = '076166a1-9f6e-11e3-b8df-3c075456b21a'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost')

        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/create_volume_response.json')
        get.return_value.status_code = 200

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(
            read_file('tests/data/zones_search.json'))

        with mock.patch('requests.get', get):
            with mock.patch('ec2stack.providers.cloudstack.zones.get_zone',
                            get_zone):
                response = self.post('/', data=data)

        self.assert_ok(response)
        assert 'CreateVolumeResponse' in response.data
Exemple #45
0
    def test_create_volume_invalid_snapshot(self):
        data = self.get_example_data()
        data['Action'] = 'CreateVolume'
        data['SnapshotId'] = 'invalid-snapshot-id'
        data['AvailabilityZone'] = 'Sandbox-simulator'
        data['Signature'] = generate_signature(data, 'POST', 'localhost')

        get_request = mock.Mock()
        get_request.return_value.text = read_file(
            'tests/data/create_volume_invalid_snapshot_response.json')
        get_request.return_value.status_code = 431

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(
            read_file('tests/data/zones_search.json'))

        with mock.patch('requests.get', get_request):
            with mock.patch('ec2stack.providers.cloudstack.zones.get_zone',
                            get_zone):
                response = self.post('/', data=data)

        self.assert_bad_request(response)
        assert 'InvalidSnapshot.NotFound' in response.data
    def test_run_instance_with_zone_and_type_(self):
        data = self.get_example_data()
        data['Action'] = 'RunInstances'
        data['InstanceType'] = 'micro'
        data['Placement.AvailabilityZone'] = 'example-zone'
        data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
        data['MinCount'] = '0'
        data['MaxCount'] = '0'
        data['SecurityGroupId.1'] = 'example-security-group-id'
        data['SecurityGroup.1'] = 'example-security-group-name'
        data['KeyName'] = 'example-ssh-key-name'
        data['UserData'] = 'example-user-data'
        data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')

        get = mock.Mock()
        get.return_value.text = read_file('tests/data/valid_run_instance.json')
        get.return_value.status_code = 200

        get_service_offering = mock.Mock()
        get_service_offering.return_value = json.loads(
            read_file('tests/data/service_offering_search.json'))

        get_zone = mock.Mock()
        get_zone.return_value = json.loads(
            read_file('tests/data/zones_search.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                    'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
                    get_service_offering):
                with mock.patch('ec2stack.providers.cloudstack.zones.get_zone',
                                get_zone):
                    response = self.post('/', data=data)

        self.assert_ok(response)
        assert 'RunInstancesResponse' in response.data