Exemplo n.º 1
0
    def test_subscription_list(self):
        client = cr.Subscriptions()
        with DumpResponse(clients=[client])('subscription_list'):
            client.get()

        with DumpResponse(clients=[client])('subscription_schema'):
            client.get_schema()
Exemplo n.º 2
0
    def test_pricing(self):
        client = cr.Pricing()
        with DumpResponse(clients=[client])('pricing_list'):
            pricing = client.list(query_params={'limit': 5})

        with DumpResponse(clients=[client])('pricing_schema'):
            client.get_schema()
Exemplo n.º 3
0
    def test_server_clone(self):
        server = self._create_a_server()

        with DumpResponse(clients=[self.client],
                          name='server_get_clone_source'):
            server = self.client.get(server['uuid'])

        with DumpResponse(clients=[self.client], name='server_clone'):
            clone = self.client.clone(server['uuid'], {
                'name': 'test cloned server name',
                'random_vnc_password': True
            })

        self.client.delete(server['uuid'])
        self.client.delete(clone['uuid'])
Exemplo n.º 4
0
    def test_profile(self):

        with DumpResponse(name='profile',
                          clients=[self.client],
                          resp_data_filter=anonymize_profile):
            profile = self.client.get()

        profile['company'] = 'Newly Set Company Name'
        with DumpResponse(name='profile_update',
                          clients=[self.client],
                          resp_data_filter=anonymize_profile,
                          req_data_filter=anonymize_profile):
            self.client.update(profile)

        profile['company'] = ''
        self.client.update(profile)
Exemplo n.º 5
0
 def setUp(self):
     super(SnapshotsTest, self).setUp()
     self.snap_client = cr.Snapshot()
     self.drive_client = cr.Drive()
     self.dump_response = DumpResponse(
         clients=[self.snap_client, self.drive_client]
     )
Exemplo n.º 6
0
    def test_list_limit(self):
        servers_to_create = 50

        print(f'\nCreating servers ({servers_to_create})')
        servers = [
            self._create_a_server(
                server_req={
                    'name': 'test server %d' % (i,),
                    'cpu': 1000,
                    'mem': 512 * 1024 ** 2,
                    'vnc_password': '******',
                }
            ) for i in range(servers_to_create)
        ]

        with DumpResponse(clients=[self.client])('server_list'):
            servers_list = self.client.list(query_params={'limit': 20})
            self.assertEqual(20, len(servers_list))

        time.sleep(10)

        print('Deleting Servers', end='', flush=True)
        for i, server in enumerate(servers):
            self.client.delete(server['uuid'])
            print(f' {i + 1}', end='', flush=True)
Exemplo n.º 7
0
    def test_server_fw_rules(self):
        policy = self.client.create(self.base_policy)

        server_def = {
            'name':
            'FirewalledServer',
            'cpu':
            1000,
            'mem':
            512 * 1024**2,
            'vnc_password':
            '******',
            "nics": [{
                "firewall_policy": policy['uuid'],
                "ip_v4_conf": {
                    "ip": None,
                    "conf": "dhcp"
                },
                "model": "virtio",
            }],
        }
        server_client = resource.Server()
        with DumpResponse(clients=[server_client])("fwpolicy_server_attach"):
            server = server_client.create(server_def)

        self.assertEqual(server['nics'][0]['firewall_policy']['uuid'],
                         policy['uuid'])

        self.client.delete(policy['uuid'])

        server = server_client.get(server['uuid'])
        self.assertIsNone(server['nics'][0]['firewall_policy'])

        server_client.delete(server['uuid'])
Exemplo n.º 8
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.client = resource.FirewallPolicy()
     self.dump_response = DumpResponse(clients=[self.client])
     self.base_policy = {
         "name":
         "My awesome policy",
         "rules": [{
             "dst_ip":
             "23",
             "direction":
             "out",
             "action":
             "drop",
             "comment":
             "Drop traffic from the VM to IP address 23.0.0.0/32"
         }, {
             "src_ip":
             "172.66.32.0/24",
             "ip_proto":
             "tcp",
             "dst_port":
             "22",
             "direction":
             "in",
             "action":
             "accept",
             "comment":
             "Allow SSH traffic to the VM from our office in Dubai"
         }, {
             "ip_proto": "tcp",
             "dst_port": "22",
             "direction": "in",
             "action": "drop",
             "comment": "Drop all other SSH traffic to the VM"
         }, {
             "src_ip":
             "!172.66.32.55",
             "ip_proto":
             "udp",
             "direction":
             "in",
             "action":
             "drop",
             "comment":
             "Drop all UDP traffic to the VM, not originating from 172.66.32.55"
         }, {
             "ip_proto":
             "tcp",
             "dst_port":
             "!1:1024",
             "direction":
             "in",
             "action":
             "drop",
             "comment":
             "Drop any traffic, to the VM with destination port not between 1-1024"
         }]
     }
     self._clean_policies()
Exemplo n.º 9
0
    def setUp(self):
        super(tagsTest, self).setUp()
        self.client = cr.Tags()
        self.dump_response = DumpResponse(clients=[self.client])

        tags = self.client.list()

        for tag in tags:
            self.client.delete(tag['uuid'])
Exemplo n.º 10
0
    def test_subscription_create(self):
        if os.environ.get('TURLO_MANUAL_TESTS', '0') == '0':
            raise unittest.SkipTest(
                "Subscriptions cannot be deleted by the user so this cannot be cleaned up. Use TURLO_MANUAL_TESTS=1 environment variable"
            )

        client = cr.Subscriptions()
        with DumpResponse(clients=[client])('subscription_create'):
            sub = client.create({
                "resource": "dssd",
                "amount": 1000 * 3 * 10,
                "period": "1 month"
            })
Exemplo n.º 11
0
 def test_list_limit(self):
     servers = [
         self._create_a_server(
             server_req={
                 'name': 'test server %d' % (i, ),
                 'cpu': 1000,
                 'mem': 512 * 1024**2,
                 'vnc_password': '******',
             }) for i in range(50)
     ]
     with DumpResponse(clients=[self.client])('server_list'):
         servers_list = self.client.list(query_params={'limit': 20})
         self.assertEqual(20, len(servers_list))
     time.sleep(10)
     for server in servers:
         self.client.delete(server['uuid'])
Exemplo n.º 12
0
    def test_libdrive_listing(self):
        with self.dump_response('libdrive_list'):
            libdrives = self.client.list(query_params={'limit': 5})

        # Select the lib drive with most interesting attributes
        libdrive_uuid = libdrives[0][
            'uuid']  # by default use the first possible
        for d in libdrives:
            if len(d['licenses']) > 0:  # pick a drive with licenses
                libdrive_uuid = d['uuid']
                break

        with self.dump_response('libdrive_get'):
            libdrive = self.client.get(libdrive_uuid)

        dc = cr.Drive()
        with DumpResponse(clients=[dc])('librdrive_get_through_drives'):
            libdrive_from_drive_url = dc.get(libdrive_uuid)

        self.assertIsNone(libdrive_from_drive_url['owner'])
        self.assertEqual(libdrive['uuid'], libdrive_from_drive_url['uuid'])
        self.assertEqual(libdrive['name'], libdrive_from_drive_url['name'])
Exemplo n.º 13
0
    def test_server_state_cycle(self):
        """Test simple server create-start-stop-delete cycle"""
        dump_response = DumpResponse(clients=[self.client])

        with dump_response('server_create_minimal'):
            server = self._create_a_server()

        self._verify_list(server, True)

        with dump_response('server_start'):
            self.client.start(server['uuid'])

        self._wait_for_status(server['uuid'], 'running')

        with dump_response('server_stop'):
            self.client.stop(server['uuid'])

        self._wait_for_status(server['uuid'], 'stopped')

        with dump_response('server_delete'):
            self.client.delete(server['uuid'])

        self._verify_list(server, False)
Exemplo n.º 14
0
    def test_tags(self):
        with self.dump_response('tags_schema'):
            self.client.get_schema()

        sc = cr.Server()
        server1 = sc.create({
            'name': 'test_server1',
            'cpu': 1000,
            'mem': 512 * 1024**2,
            'vnc_password': '******'
        })
        server2 = sc.create({
            'name': 'test_server2',
            'cpu': 1000,
            'mem': 512 * 1024**2,
            'vnc_password': '******'
        })

        dc = cr.Drive()
        drive = dc.create({
            'name': 'test_drive',
            'size': 1000**3,
            'media': 'disk'
        })

        ip = cr.IP().list()[0]
        vlan = cr.VLAN().list()[0]

        with self.dump_response('tags_create'):
            tag1 = self.client.create({'name': 'MyGroupOfThings'})

        with self.dump_response('tags_create_with_resource'):
            tag2 = self.client.create({
                'name':
                'TagCreatedWithResource',
                'resources': [
                    server1['uuid'], server2['uuid'], drive['uuid'],
                    ip['uuid'], vlan['uuid']
                ]
            })
        with self.dump_response('tags_list'):
            self.client.list()

        with self.dump_response('tags_list_detail'):
            self.client.list_detail()

        with self.dump_response('tags_get'):
            self.client.get(tag2['uuid'])

        with self.dump_response('tags_update_resources'):
            self.client.update(
                tag2['uuid'], {
                    'name': 'TagCreatedWithResource',
                    'resources': [server1['uuid'], drive['uuid']]
                })

        server2['tags'] = [tag1['uuid'], tag2['uuid']]
        with DumpResponse(clients=[sc], name='tags_update_tag_from_resource'):
            sc.update(server2['uuid'], server2)

        with self.dump_response('tags_list_resource'):
            self.client.servers(tag1['uuid'])

        time.sleep(30)

        dc.delete(drive['uuid'])
        sc.delete(server1['uuid'])
        sc.delete(server2['uuid'])

        with self.dump_response('tags_delete'):
            self.client.delete(tag1['uuid'])
        self.client.delete(tag2['uuid'])
Exemplo n.º 15
0
 def test_get_schema(self):
     with DumpResponse(name='profile_schema', clients=[self.client]):
         self.client.get_schema()
Exemplo n.º 16
0
    def test_server_runtime(self):
        dv = cr.Drive()
        drive_def_1 = {
            'name': 'test_drive_1',
            'size': '1024000000',
            'media': 'disk',
        }
        drive1 = dv.create(drive_def_1)
        self._wait_for_status(drive1['uuid'], 'unmounted', client=dv)

        server_def = {
            'name':
            'testServerAcc',
            'cpu':
            1000,
            'mem':
            512 * 1024**2,
            'vnc_password':
            '******',
            'drives': [
                {
                    "device": "virtio",
                    "dev_channel": "0:0",
                    "drive": drive1['uuid'],
                    "boot_order": 1
                },
            ],
            "nics": [{
                "ip_v4_conf": {
                    "ip": None,
                    "conf": "dhcp"
                },
                "model": "virtio",
            }],
        }

        server = self.client.create(server_def)

        self._verify_list(server, True)

        self.client.start(server['uuid'])

        self._wait_for_status(server['uuid'], 'running')

        with DumpResponse(clients=[self.client], name='server_get_running'):
            server_def = self.client.get(server['uuid'])

        self.assertEqual(server_def['runtime']['nics'][0]['interface_type'],
                         'public')
        self.assertIsNotNone(server_def['runtime']['nics'][0]['ip_v4'])

        # check runtime call
        runtime = self.client.runtime(server['uuid'])
        self.assertEqual(runtime['nics'][0]['interface_type'], 'public')
        self.assertIsNotNone(runtime['nics'][0]['ip_v4'])

        self.client.stop(server['uuid'])
        self._wait_for_status(server['uuid'], 'stopped')

        self.client.delete(server['uuid'])
        self._verify_list(server, False)

        dv.delete(drive1['uuid'])
        self._wait_deleted(drive1['uuid'], client=dv)
Exemplo n.º 17
0
    def test_guest_context(self):
        dc = cr.Drive()
        sc = cr.Server()
        gcc = cr.GlobalContext()
        dump_response = DumpResponse(clients=[sc, dc, gcc])
        # ensure empty global context
        gcc.update({})

        puuid, p_pass = self._get_persistent_image_uuid_and_pass()
        LOG.debug('Clone the persistent image')
        d1 = dc.clone(puuid, {'name': 'test_clone_1'})
        from uuid import uuid4
        g_def = {
            "name":
            "test_server",
            "cpu":
            1000,
            "mem":
            1024**3,
            'vnc_password':
            str(uuid4())[:18].replace('-', ''),
            'drives': [
                {
                    "device": "virtio",
                    "dev_channel": "0:0",
                    "drive": d1['uuid'],
                    "boot_order": 1
                },
            ],
            "nics": [
                {
                    "ip_v4_conf": {
                        "ip": None,
                        "conf": "dhcp"
                    },
                    "model": "virtio",
                },
            ],
            "meta": {
                "ssh_public_key":
                "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCy4XpmD3kEfRZ+LCwFh3Xmqrkm7rSiDu8v+ZCTOA3vlNjmy/ZOc3vy9Zr+IhWPP4yipiApkGRsBM63tTgnxqUUn/WU7qkbBNktZBcs5p7Mj/zO4ZHkk4VoTczFzHlPGwuak2P4wTftEj7sU8IRutaAbMoKj4AMuFF50j4sIgF7P5b5FtTIM2b5HSW8BlDz10b67+xsj6s3Jv05xxbBs+RWj+v7D5yjMVeeErXoSui8dlHpUu6QOVKn8LLmdpxvehc6ns8yW7cbQvWmLjOICMnm6BXdVtOKWBncDq9FGLmKF3fUeZZPbv79Z7dyZs+xGZGMHbpaNHpuY9QhNS/hQ5D5 dave@hal"
            }
        }

        LOG.debug('Creating guest with drive')

        with dump_response('guest_for_context'):
            g1 = sc.create(g_def)

        self._wait_for_status(d1['uuid'], 'mounted', client=dc)

        sc.start(g1['uuid'])

        self._wait_for_status(g1['uuid'], 'running', client=sc)

        LOG.debug('Refetch guest configurations')

        g1 = sc.get(g1['uuid'])

        LOG.debug('Get the assigned ips')
        ip1 = g1['nics'][0]['runtime']['ip_v4']["uuid"]

        self._wait_for_open_socket(ip1, 22, timeout=60, close_on_success=True)

        from fabric.api import settings as fabric_settings
        from fabric import tasks, api

        fab_kwargs = {
            "warn_only": True,
            "abort_on_prompts": True,
            "use_ssh_config": p_pass is None
        }
        LOG.debug('Using fabric config {}'.format(fab_kwargs))
        if p_pass is not None:
            fab_kwargs['password'] = p_pass
            LOG.debug(
                'Using a password to SSH to the servers ( not using ssh config )'
            )

        dump_path = dump_response.response_dump.dump_path

        #command_template = r"read -t 1 -d $'\004' DISCARD < /dev/ttyS1; " \
        #                   r'echo -en "<\n{}\n>" > /dev/ttyS1 && read -t 3 READVALUE < /dev/ttyS1 && echo $READVALUE'
        self.command_template = r'v=$(read -t 13 READVALUE < /dev/ttyS1 && echo $READVALUE & sleep 1; echo -en "<\n{}\n>" > /dev/ttyS1; wait %1); echo $v'

        LOG.debug('Test the guest context')

        LOG.debug('Check single value retrieval')
        self.check_key_retrieval(g_def, 'context_single_value', 'name',
                                 dump_path, fab_kwargs, ip1, fabric_settings,
                                 tasks, api)

        ##########################################
        LOG.debug('Check key retrieval')
        self.check_key_retrieval(g_def, 'context_single_value_ssh_key',
                                 '/meta/ssh_public_key', dump_path, fab_kwargs,
                                 ip1, fabric_settings, tasks, api)

        ##########################################
        LOG.debug('Check complete context retrieval')
        self.check_all_retrieval(g_def, 'context_all', dump_path, fab_kwargs,
                                 ip1, fabric_settings, tasks, api)

        ##########################################
        ##########################################
        ##########################################
        ##########################################
        LOG.debug('Check context dynamic update')
        g_def['name'] += '_renamed'
        g_def['meta']['another_key'] = 'a value or something'

        upd_res = sc.update(g1['uuid'], g_def)
        self.assertEqual(g_def['name'], upd_res['name'])

        LOG.debug('Check single value retrieval')

        self.check_key_retrieval(g_def, 'context_single_value_dynamic', 'name',
                                 dump_path, fab_kwargs, ip1, fabric_settings,
                                 tasks, api)

        ##########################################
        LOG.debug('Check key retrieval')
        self.check_key_retrieval(g_def,
                                 'context_single_value_another_key_dynamic',
                                 '/meta/another_key', dump_path, fab_kwargs,
                                 ip1, fabric_settings, tasks, api)

        ##########################################
        LOG.debug('Check complete context retrieval')
        self.check_all_retrieval(g_def, 'context_all_dynamic', dump_path,
                                 fab_kwargs, ip1, fabric_settings, tasks, api)

        ###########################################
        ###########################################
        ###########################################
        with dump_response('update_global_context'):
            gcc.update({'new_global_key': 'new_global_val'})

        LOG.debug('Check global context retrieval')
        command = self.command_template.format(
            '/global_context/new_global_key')
        expected_val = 'new_global_val'
        res_string = self.get_single_ctx_val(command, expected_val, fab_kwargs,
                                             ip1, fabric_settings, tasks, api)
        self.assertEqual(res_string, expected_val)
        self.dump_ctx_command(command, res_string,
                              'global_context_single_value', dump_path)

        self.check_all_retrieval(g_def, 'global_context_all', dump_path,
                                 fab_kwargs, ip1, fabric_settings, tasks, api)

        LOG.debug('Stopping guest')
        sc.stop(g1['uuid'])
        self._wait_for_status(g1['uuid'], 'stopped', client=sc, timeout=40)

        LOG.debug('Delete guest')
        sc.delete(g1['uuid'])

        LOG.debug('Delete drive')
        dc.delete(d1['uuid'])
        self._wait_deleted(d1['uuid'], client=dc)
Exemplo n.º 18
0
 def test_licenses(self):
     client = cr.Licenses()
     with DumpResponse(clients=[client])('licenses_list'):
         licenses = client.get()
     with DumpResponse(clients=[client])('licenses_schema'):
         client.get_schema()
Exemplo n.º 19
0
 def test_ledger(self):
     client = cr.Ledger()
     with DumpResponse(clients=[client])('ledger_list'):
         ledger = client.get()
     with DumpResponse(clients=[client])('ledger_schema'):
         client.get_schema()
Exemplo n.º 20
0
 def test_currentusage(self):
     client = cr.CurrentUsage()
     with DumpResponse(clients=[client])('currentusage_list'):
         currentusage = client.get()
     with DumpResponse(clients=[client])('currentusage_schema'):
         client.get_schema()
Exemplo n.º 21
0
 def test_balance(self):
     client = cr.Balance()
     with DumpResponse(clients=[client])('balance_list'):
         balance = client.get()
     with DumpResponse(clients=[client])('balance_schema'):
         client.get_schema()
Exemplo n.º 22
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.client = cr.Server()  # create a resource handle object
     self.dump_response = DumpResponse(clients=[self.client])
Exemplo n.º 23
0
 def setUp(self):
     super(LibraryDriveTest, self).setUp()
     self.client = cr.LibDrive()
     self.dump_response = DumpResponse(clients=[self.client])
Exemplo n.º 24
0
    def test_server_nics(self):
        server = self._create_a_server()

        subs_client = cr.Subscriptions()

        vlan_client = cr.VLAN()
        vlans = vlan_client.list()
        if not vlans:
            subs_client.create({
                'resource': 'vlan',
                'amount': 1,
                'period': '1 month'
            })
            vlans = vlan_client.list()
        vlan_uuid = vlans[0]['uuid']

        ip_client = cr.IP()
        ips = ip_client.list()
        free_ips = [ip for ip in ips if ip['server'] is None]
        if not free_ips:
            subs_client.create({
                'resource': 'ip',
                'amount': 1,
                'period': '1 month'
            })
            ips = ip_client.list()
            free_ips = [ip for ip in ips if ip['server'] is None]

        ip_uuid = free_ips[0]['uuid']

        server['nics'] = [{'vlan': vlan_uuid}]

        with DumpResponse(clients=[self.client],
                          name='server_add_private_nic'):
            server = self.client.update(server['uuid'], server)

        server['nics'] = [{'ip_v4_conf': {'conf': 'dhcp'}, 'model': 'e1000'}]
        with DumpResponse(clients=[self.client], name='server_add_dhcp_nic'):
            server = self.client.update(server['uuid'], server)

        server['nics'] = [{
            'ip_v4_conf': {
                'conf': 'dhcp'
            },
            'model': 'e1000'
        }, {
            'vlan': vlan_uuid
        }]
        server = self.client.update(server['uuid'], server)
        with DumpResponse(clients=[self.client], name='server_get_two_nics'):
            server = self.client.get(server['uuid'])

        server['nics'][0]['ip_v4_conf'] = {'conf': 'static', 'ip': ip_uuid}
        with DumpResponse(clients=[self.client],
                          name='server_change_nic_to_static'):
            server = self.client.update(server['uuid'], server)

        server['nics'] = [server['nics'][1], server['nics'][0]]
        with DumpResponse(clients=[self.client], name='server_rearrange_nics'):
            server = self.client.update(server['uuid'], server)

        private_mac = server['nics'][0]['mac']
        server['nics'] = [{'ip_v4_conf': {'conf': 'dhcp'}, 'mac': private_mac}]
        with DumpResponse(clients=[self.client],
                          name='server_del_and_change_nic'):
            server = self.client.update(server['uuid'], server)

        server['nics'] = [{'ip_v4_conf': {'conf': 'manual'}}]
        with DumpResponse(clients=[self.client], name='server_add_manual_nic'):
            server = self.client.update(server['uuid'], server)

        self.client.delete(server['uuid'])
Exemplo n.º 25
0
 def setUp(self):
     super(IPBasicTest, self).setUp()
     self.client = cr.IP()
     self.dump_response = DumpResponse(clients=[self.client])
Exemplo n.º 26
0
 def test_get_schema(self):
     with DumpResponse(clients=[self.client], name='server_schema'):
         self.client.get_schema()
Exemplo n.º 27
0
 def setUp(self):
     super(CapabilitiesTest, self).setUp()
     self.client = cr.Capabilites()
     self.dump_response = DumpResponse(clients=[self.client])
Exemplo n.º 28
0
    def test_create_full_server(self):
        dv = cr.Drive()
        dump_response = DumpResponse(clients=[self.client])

        drive_def_1 = {
            'name': 'test_drive_1',
            'size': '1024000000',
            'media': 'disk',
        }

        drive_def_2 = {
            'name': 'test_drive_2',
            'size': '1024000000',
            'media': 'cdrom',
        }

        drive1 = dv.create(drive_def_1)
        drive2 = dv.create(drive_def_2)

        self._wait_for_status(drive1['uuid'], 'unmounted', client=dv)
        self._wait_for_status(drive2['uuid'], 'unmounted', client=dv)

        server_definition = {
            "requirements": [],
            "name":
            "test_acc_full_server",
            "cpus_instead_of_cores":
            False,
            "tags": [],
            "mem":
            256 * 1024**2,
            "nics": [{
                "ip_v4_conf": {
                    "conf": "dhcp"
                },
            }],
            "enable_numa":
            False,
            "cpu":
            1000,
            "drives": [
                {
                    "device": "virtio",
                    "dev_channel": "0:0",
                    "drive": drive1['uuid'],
                    "boot_order": 1
                },
                {
                    "device": "ide",
                    "dev_channel": "0:0",
                    "drive": drive2['uuid'],
                },
            ],
            "smp":
            1,
            "hv_relaxed":
            False,
            "hv_tsc":
            False,
            "meta": {
                "description": "A full server with description"
            },
            "vnc_password":
            "******",
        }

        with dump_response('server_create_full'):
            server = self.client.create(server_definition)

        # TODO: Uncomment this when the guest_drive definition order changes reach production
        #self._verify_list(server, True)

        self.client.delete(server['uuid'])

        self._verify_list(server, False)

        dv.delete(drive1['uuid'])
        dv.delete(drive2['uuid'])

        self._wait_deleted(drive1['uuid'], client=dv)
        self._wait_deleted(drive2['uuid'], client=dv)
Exemplo n.º 29
0
 def test_discount(self):
     client = cr.Discount()
     with DumpResponse(clients=[client])('discount_list'):
         discount = client.get()
     with DumpResponse(clients=[client])('discount_schema'):
         client.get_schema()