Beispiel #1
0
    def test_new_address(self):
        # We don't have a way to ask for new IP address from Serveradmin
        # and lock it for us. The method below will usually work fine.
        # When it starts failing, we must develop retry method.
        new_address = get_next_address(VM_NET, 2)

        change_address(VM_HOSTNAME, new_address, offline=True)

        obj = Query({'hostname': VM_HOSTNAME}, ['intern_ip']).get()
        self.assertEqual(obj['intern_ip'], new_address)
        with _get_vm(VM_HOSTNAME) as vm:
            vm.run(cmd('ip a | grep {}', new_address))
        self.check_vm_present()
Beispiel #2
0
    def setUp(self):
        """Initialize VM object before every test

        Get object from Serveradmin and initialize it to safe defaults.
        Don't assign VM to any of HVs yet!
        """
        super().setUp()

        # Check that enough HVs are available.
        self.route_network = Query(
            {
                'hostname': VM_NET
            },
            ['route_network'],
        ).get()['route_network']

        self.datacenter_type = Query(
            {
                'hostname': self.route_network
            },
            ['datacenter_type'],
        ).get()['datacenter_type']

        self.hvs = [
            Hypervisor(o) for o in Query(
                {
                    'environment': 'testing',
                    'servertype': 'hypervisor',
                    'state': 'online',
                    'vlan_networks': self.route_network,
                }, HYPERVISOR_ATTRIBUTES)
        ]

        if self.datacenter_type == 'kvm.dct':
            assert len(self.hvs) >= 2, 'Not enough testing hypervisors found'

        # Cleanup all leftovers from previous tests or failures.
        clean_all(self.route_network, self.datacenter_type, VM_HOSTNAME)

        # Create subject VM object
        self.vm_obj = Query().new_object('vm')
        self.vm_obj['backup_disabled'] = True
        self.vm_obj['disk_size_gib'] = 3
        self.vm_obj['environment'] = 'testing'
        self.vm_obj['hostname'] = VM_HOSTNAME
        self.vm_obj['hypervisor'] = None
        self.vm_obj['intern_ip'] = get_next_address(VM_NET, 1)
        self.vm_obj['memory'] = 2048
        self.vm_obj['no_monitoring'] = True
        self.vm_obj['num_cpu'] = 2
        self.vm_obj['os'] = 'buster'
        self.vm_obj['project'] = 'test'
        self.vm_obj['puppet_environment'] = None
        self.vm_obj['puppet_ca'] = 'testing-puppetca.innogames.de'
        self.vm_obj['puppet_master'] = 'puppet-lb.test.innogames.net'
        self.vm_obj['repositories'] = [
            'int:basebuster:stable',
            'int:innogames:stable',
        ]
        self.vm_obj['state'] = 'online'

        if self.datacenter_type == 'aws.dct':
            self.vm_obj['aws_image_id'] = 'ami-0e2b90ca04cae8da5'  # buster
            self.vm_obj['aws_instance_type'] = 't2.micro'
            self.vm_obj['aws_key_name'] = 'eu-central-1-key'
            self.vm_obj['disk_size_gib'] = 8

        self.vm_obj.commit()

        # It would be enough to create SGs in AWS once but with parallel runs
        # we can't really test if sync has already been performed.
        if self.datacenter_type == 'aws.dct':
            fw_api = api.get('firewall')
            fw_api.update_config([self.route_network])

        self.uid_name = '{}_{}'.format(
            self.vm_obj['object_id'],
            self.vm_obj['hostname'],
        )

        # Make sure we can make a fresh build
        clean_cert(self.vm_obj)