def test_delete_instance(self):
        get = mock.Mock()
        get.return_value.text = read_file('tests/data/valid_async_destroy_vm.json')
        get.return_value.status_code = 200

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

        get_async_result = mock.Mock()
        get_async_result.return_value = json.loads(read_file('tests/data/valid_run_instance.json'))

        publickey_storage['admin'] = 'testkey'

        with mock.patch('requests.get', get):
            with mock.patch(
                    'gstack.controllers.get_item_with_name',
                    get_instance
                ):
                with mock.patch(
                    'gstack.controllers.operations._get_async_result',
                    get_async_result
                ):
                    headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
                    response = self.delete('/compute/v1/projects/admin/zones/examplezone/instances/instancename', headers=headers)

        self.assert_ok(response)
    def test_delete_instance(self):
        get = mock.Mock()
        get.return_value.text = read_file(
            'tests/data/valid_async_destroy_vm.json')
        get.return_value.status_code = 200

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

        get_async_result = mock.Mock()
        get_async_result.return_value = json.loads(
            read_file('tests/data/valid_run_instance.json'))

        publickey_storage['admin'] = 'testkey'

        with mock.patch('requests.get', get):
            with mock.patch(
                'gstack.controllers.get_item_with_name',
                get_instance
            ):
                with mock.patch(
                    'gstack.controllers.operations._get_async_result',
                    get_async_result
                ):
                    headers = {
                        'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
                    response = self.delete(
                        '/compute/v1/projects/admin/zones/examplezone/instances/instancename', headers=headers)

        self.assert_ok(response)
Exemple #3
0
    def test_get_project(self):
        get = mock.Mock()
        get.return_value = json.loads(read_file('tests/data/valid_get_account.json'))

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

        with mock.patch('requests.get', get_tags):
            with(mock.patch('gstack.controllers.get_item_with_name', get)):
                headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
                response = self.get('/compute/v1/projects/accountname', headers=headers)

        self.assert_ok(response)
    def test_set_metadata(self):
        data = {
            'items': [{
                'key': 'sshKeys',
                'value': 'root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqQuui+xCVPXaFD4cP2MuWnDlktp9vMT/SNzF17UiAzKEbxT\
                                        /mPayTDArDbY/BgGYC5bHuGlb/eE1r4EGpwSXZitGkTI4ThldrSp0Em7psO8AibdpYuFxlOmDFp9wK\
                                        VD6xbY2HT1ySwvKi+ZwSR5yHcEKq15eV4eez/3qC1vIcssKmwu5+ZBneZAvWAfxHEKsQU0dsCVvHdn8\
                                        g7tFXXtg4QCGtE4yzK5v3/+f1AdtIi4hvJoMyi8MV0KSa8e/ravdHbgj44PncFBB8O6epVdXPbClZwt\
                                        kz9D6GEQaOArxk9tX8YEgTFnmsnNuaoZgs7giMj2N7jQe2qXh5R0nsTTuH brogand@microvac'
            }],
            'kind': 'compute#metadata'
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/admin/setCommonInstanceMetadata', data=data, headers=headers)

        self.assert_ok(response)
Exemple #5
0
    def test_add_firewall(self):
        data = {
            "kind": "compute#firewall",
            "network":
            "https://*****:*****@darrenbrogan.ie/global/networks/default",
            "description": "",
            "sourceRanges": ["0.0.0.0/0"],
            "allowed": [{
                "IPProtocol": "6",
                "ports": ["22"]
            }],
            "name": "ssh"
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization':
                'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/exampleproject/global/firewalls',
                data=data,
                headers=headers)

        self.assert_ok(response)
    def test_add_firewall(self):
        data = {
            "kind": "compute#firewall",
            "network": "https://*****:*****@darrenbrogan.ie/global/networks/default",
            "description": "",
            "sourceRanges": ["0.0.0.0/0"],
            "allowed": [{
                "IPProtocol": "6",
                "ports": ["22"]
            }],
            "name": "ssh"
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/exampleproject/global/firewalls', data=data, headers=headers)

        self.assert_ok(response)
Exemple #7
0
    def test_delete_network_network_not_found(self):

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

        get_networks = mock.Mock()
        get_networks.return_value = None

        with mock.patch('requests.get', get):
            with mock.patch('gstack.controllers.get_item_with_name',
                            get_networks):
                headers = {
                    'authorization':
                    'Bearer ' + str(GStackAppTestCase.access_token),
                }

                response = self.delete(
                    '/compute/v1/projects/exampleproject/global/networks/invalidnetworkname',
                    headers=headers)

        self.assert_not_found(response)
        assert 'The resource \'/compute/v1/projects/exampleproject/global/networks/invalidnetworkname\'' \
            in response.data
Exemple #8
0
    def test_add_network(self):
        data = {
            'IPv4Range': '10.0.0.0/8',
            'kind': 'compute#network',
            'name': 'networkname',
            'description': ''
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization':
                'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/admin/global/networks',
                data=data,
                headers=headers)

        self.assert_ok(response)
    def test_set_metadata(self):
        data = {
            'items': [{
                'key':
                'sshKeys',
                'value':
                'root:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqQuui+xCVPXaFD4cP2MuWnDlktp9vMT/SNzF17UiAzKEbxT\
                                        /mPayTDArDbY/BgGYC5bHuGlb/eE1r4EGpwSXZitGkTI4ThldrSp0Em7psO8AibdpYuFxlOmDFp9wK\
                                        VD6xbY2HT1ySwvKi+ZwSR5yHcEKq15eV4eez/3qC1vIcssKmwu5+ZBneZAvWAfxHEKsQU0dsCVvHdn8\
                                        g7tFXXtg4QCGtE4yzK5v3/+f1AdtIi4hvJoMyi8MV0KSa8e/ravdHbgj44PncFBB8O6epVdXPbClZwt\
                                        kz9D6GEQaOArxk9tX8YEgTFnmsnNuaoZgs7giMj2N7jQe2qXh5R0nsTTuH brogand@microvac'
            }],
            'kind':
            'compute#metadata'
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization':
                'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/admin/setCommonInstanceMetadata',
                data=data,
                headers=headers)

        self.assert_ok(response)
    def test_aggregated_list_instances(self):
        get = mock.Mock()
        get.return_value.text = read_file('tests/data/valid_describe_instances.json')
        get.return_value.status_code = 200

        get_zones = mock.Mock()
        get_zones.return_value = json.loads(read_file('tests/data/valid_describe_zone.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                'gstack.controllers.zones._get_zones',
                get_zones
            ):
                headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
                response = self.get('/compute/v1/projects/projectid/aggregated/instances', headers=headers)

        self.assert_ok(response)
Exemple #11
0
    def test_aggregated_list_disks(self):

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

        get_zones = mock.Mock()
        get_zones.return_value = json.loads(read_file('tests/data/valid_describe_zone.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                'gstack.controllers.zones._get_zones',
                get_zones
            ):
                headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
                response = self.get('/compute/v1/projects/projectid/aggregated/disks', headers=headers)

        self.assert_ok(response)
    def test_get_instance(self):
        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):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/zones/examplezone/instances/instancename', headers=headers)

        self.assert_ok(response)
Exemple #13
0
    def test_query_operation(self):
        get = mock.Mock()
        get.return_value.text = read_file('tests/data/destroy_vm_async_pending.json')
        get.return_value.status_code = 200

        with mock.patch('requests.get', get):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/global/operations/exampleoperation', headers=headers)

        self.assert_ok(response)
    def test_get_region(self):

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

        with mock.patch("requests.get", get):
            headers = {"authorization": "Bearer " + str(GStackAppTestCase.access_token)}
            response = self.get("/compute/v1/projects/exampleproject/regions/regionname", headers=headers)

        self.assert_ok(response)
Exemple #15
0
    def test_get_zone(self):

        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):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/zones/zonename', headers=headers)

        self.assert_ok(response)
    def test_list_machine_types(self):

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

        with mock.patch('requests.get', get):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/zones/examplezone/machineTypes', headers=headers)

        self.assert_ok(response)
    def test_delete_network(self):

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

        get_networks = mock.Mock()
        get_networks.return_value = json.loads(
            read_file('tests/data/valid_get_security_group.json'))

        with mock.patch('requests.get', get):
            with mock.patch('gstack.controllers.get_item_with_name', get_networks):
                headers = {
                    'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
                }

                response = self.delete(
                    '/compute/v1/projects/exampleproject/global/networks/networkname', headers=headers)

        self.assert_ok(response)
Exemple #18
0
    def test_list_machine_types_with_name_filter(self):

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

        with mock.patch('requests.get', get):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get(
                '/compute/v1/projects/projectid/zones/zonename/machineTypes?filter=name+eq+machinetypename',
                headers=headers)

        self.assert_ok(response)
    def test_get_machine_type_machine_type_not_found(self):

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

        with mock.patch('requests.get', get):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/zones/examplezone/machineTypes/invalidmachinetypename', headers=headers)

        self.assert_not_found(response)
        assert 'The resource \'/compute/v1/projects/exampleproject/zones/examplezone/machineTypes/invalidmachinetypename\' was not found' \
                in response.data
Exemple #20
0
    def test_get_image_image_not_found(self):

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

        with mock.patch('requests.get', get):
            headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get('/compute/v1/projects/exampleproject/global/images/imagename', headers=headers)

        self.assert_not_found(response)
        assert 'The resource \'/compute/v1/projects/exampleproject/global/images/imagename\' was not found' \
                in response.data
Exemple #21
0
    def test_get_firewall(self):

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
            response = self.get(
                '/compute/v1/projects/exampleproject/global/firewalls/securitygroupname', headers=headers)

        self.assert_ok(response)
    def test_delete_firewall(self):

        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):
            headers = {
                'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.delete(
                '/compute/v1/projects/exampleproject/global/firewalls/firewallname', headers=headers)

        self.assert_ok(response)
Exemple #23
0
    def test_list_disks_with_name_filter(self):

        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):

            headers = {
                'authorization':
                'Bearer ' + str(GStackAppTestCase.access_token)
            }
            response = self.get(
                '/compute/v1/projects/projectid/zones/zonename/disks?filter=name+eq+volumename',
                headers=headers)

        self.assert_ok(response)
Exemple #24
0
    def _auth_example_user(self):
        data = {}
        data['code'] = 'hjrZryvgLYo3R833NkHHV8jYmxQhsD8TjKWzOm2f'
        data['grant_type'] = 'authorization_code'
        data['client_id'] = 'ExampleAPIKey'
        data['client_secret'] = 'eXmaPlEm8XQwezvLOd10Qt3wXH7j9mRgaKbEg3nRDnj7FtlF3yx54EWd9mR5sB1ec5LQDV6gjpy6sfDo6ndUeeww'
        data['redirect_uri'] = 'http://localhost:8000'

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

        with mock.patch('requests.get', get):
            self.get('/oauth2/auth?scope=example&redirect_uri=http://127.0.0.1:9999&response_type=code&client_id=ExampleAPIKey&access_type=offline')
            response = self.post_html('/oauth2/token', data=data)

        GStackAppTestCase.access_token = json.loads(response.data)['access_token']

        self.assert_ok(response)
    def _auth_example_user(self):
        data = {}
        data['code'] = 'hjrZryvgLYo3R833NkHHV8jYmxQhsD8TjKWzOm2f'
        data['grant_type'] = 'authorization_code'
        data['client_id'] = 'ExampleAPIKey'
        data[
            'client_secret'] = 'eXmaPlEm8XQwezvLOd10Qt3wXH7j9mRgaKbEg3nRDnj7FtlF3yx54EWd9mR5sB1ec5LQDV6gjpy6sfDo6ndUeeww'
        data['redirect_uri'] = 'http://localhost:8000'

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

        with mock.patch('requests.get', get):
            self.get(
                '/oauth2/auth?scope=example&redirect_uri=http://127.0.0.1:9999&response_type=code&client_id=ExampleAPIKey&access_type=offline')
            response = self.post_html('/oauth2/token', data=data)

        GStackAppTestCase.access_token = json.loads(
            response.data)['access_token']

        self.assert_ok(response)
    def test_add_network(self):
        data = {
            'IPv4Range': '10.0.0.0/8',
            'kind': 'compute#network',
            'name': 'networkname',
            'description': ''
        }

        data = json.dumps(data)

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

        with mock.patch('requests.get', get):
            headers = {
                'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
            }

            response = self.post_json(
                '/compute/v1/projects/admin/global/networks', data=data, headers=headers)

        self.assert_ok(response)
    def test_add_instance(self):
        data = {
            'kind':  'compte#instance',
            'machineType':  'https://*****:*****@darrenbrogan.ie/zones/ch-gva-2/machineTypes/machinetypename',
            'description':  '',
            'tags': {
                'items': []
            },
            'disks': [{
                'deviceName':  'machinetypename',
                'initializeParams': {
                    'diskName':  'machinetypename',
                    'sourceImage':  'https://*****:*****@darrenbrogan.ie/global/images/imagename'
                },
                'autoDelete': False,
                'boot': True,
                'mode':  'READ_WRITE',
                'type':  'PERSISTENT'
            }],
            'metadata': {
                'items': [],
                'kind':  'compte#metadata'
            },
            'networkInterfaces': [{
                'accessConfigs': [{
                    'type':  'ONE_TO_ONE_NAT',
                    'name':  'External NAT'
                }],
                'network':  'https://*****:*****@darrenbrogan.ie/global/networks/networkname'
            }],
            'name':  'foobar'
        }

        publickey_storage['admin'] = 'testkey'

        data = json.dumps(data)

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

        get_templates = mock.Mock()
        get_templates.return_value = json.loads(
            read_file('tests/data/valid_get_image.json'))

        get_zones = mock.Mock()
        get_zones.return_value = json.loads(
            read_file('tests/data/valid_get_zone.json'))

        get_service_offerings = mock.Mock()
        get_service_offerings.return_value = json.loads(
            read_file('tests/data/valid_get_service_offering.json'))

        get_networks = mock.Mock()
        get_networks.return_value = json.loads(
            read_file('tests/data/valid_get_security_group.json'))

        get_async_result = mock.Mock()
        get_async_result.return_value = json.loads(
            read_file('tests/data/valid_run_instance.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                'gstack.controllers.images.get_template_by_name',
                get_templates
            ):
                with mock.patch(
                    'gstack.controllers.zones.get_zone_by_name',
                    get_zones
                ):
                    with mock.patch(
                            'gstack.controllers.machine_type.get_machinetype_by_name',
                            get_service_offerings
                    ):
                        with mock.patch(
                                'gstack.controllers.networks.get_network_by_name',
                                get_networks
                        ):
                            with mock.patch(
                                'gstack.controllers.operations._get_async_result',
                                get_async_result
                            ):
                                headers = {
                                    'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
                                }

                                response = self.post_json(
                                    '/compute/v1/projects/admin/zones/zonename/instances', data=data, headers=headers)

        self.assert_ok(response)
    def test_add_instance(self):
        data = {
             'kind':  'compte#instance',
             'machineType':  'https://*****:*****@darrenbrogan.ie/zones/ch-gva-2/machineTypes/machinetypename',
             'description':  '',
             'tags': {
                 'items': []
             },
             'disks': [{
                 'deviceName':  'machinetypename',
                 'initializeParams': {
                     'diskName':  'machinetypename',
                     'sourceImage':  'https://*****:*****@darrenbrogan.ie/global/images/imagename'
                 },
                 'autoDelete': False,
                 'boot': True,
                 'mode':  'READ_WRITE',
                 'type':  'PERSISTENT'
             }],
             'metadata': {
                 'items': [],
                 'kind':  'compte#metadata'
             },
             'networkInterfaces': [{
                 'accessConfigs': [{
                     'type':  'ONE_TO_ONE_NAT',
                     'name':  'External NAT'
                 }],
                 'network':  'https://*****:*****@darrenbrogan.ie/global/networks/networkname'
             }],
             'name':  'foobar'
        }

        publickey_storage['admin'] = 'testkey'

        data = json.dumps(data)

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

        get_templates = mock.Mock()
        get_templates.return_value = json.loads(read_file('tests/data/valid_get_image.json'))

        get_zones = mock.Mock()
        get_zones.return_value = json.loads(read_file('tests/data/valid_get_zone.json'))

        get_service_offerings = mock.Mock()
        get_service_offerings.return_value = json.loads(read_file('tests/data/valid_get_service_offering.json'))

        get_networks = mock.Mock()
        get_networks.return_value = json.loads(read_file('tests/data/valid_get_security_group.json'))

        get_async_result = mock.Mock()
        get_async_result.return_value = json.loads(read_file('tests/data/valid_run_instance.json'))

        with mock.patch('requests.get', get):
            with mock.patch(
                'gstack.controllers.images.get_template_by_name',
                get_templates
            ):
                with mock.patch(
                    'gstack.controllers.zones.get_zone_by_name',
                    get_zones
                ):
                     with mock.patch(
                        'gstack.controllers.machine_type.get_machinetype_by_name',
                        get_service_offerings
                    ):
                         with mock.patch(
                            'gstack.controllers.networks.get_network_by_name',
                            get_networks
                        ):
                            with mock.patch(
                                'gstack.controllers.operations._get_async_result',
                                get_async_result
                            ):
                                headers = {
                                    'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
                                }

                                response = self.post_json('/compute/v1/projects/admin/zones/zonename/instances', data=data, headers=headers)

        self.assert_ok(response)