Exemplo n.º 1
0
    def build_config_from_base_and_addon(self, directory, cmd):
        #from fabs.ucsm import ucsm

        with open(os.path.join(directory, 'base.conf')) as f:
            conf_as_string = f.read()
        addon_config_name = cmd.split(' with ')[-1]
        with open(os.path.join(directory, addon_config_name)) as f:
            conf_as_string += f.read()
            conf_as_string += self.devstack_conf_addon
            conf_as_string = conf_as_string.replace('{controller_ip}', self.status.get_first(role='controller', parameter='ip'))
            conf_as_string = conf_as_string.replace('{controller_name}', self.status.get_first(role='controller', parameter='hostname'))
            conf_as_string = conf_as_string.replace('{nova_ips}', ','.join(self.status.get(role='compute', parameter='ip')))
            conf_as_string = conf_as_string.replace('{nova_ips}', ','.join(self.status.get(role='compute', parameter='ip')))
            #conf_as_string = conf_as_string.replace('{neutron_ips}', ','.join(self.status.get(role='network', parameter='ip')))
            if 'ucsm' in addon_config_name:
                ucsm_ip = self.status.get_first(role='ucsm', parameter='ip')
                ucsm_user = self.status.get_first(role='ucsm', parameter='user')
                ucsm_password = self.status.get_first(role='ucsm', parameter='password')
                ucsm_host_list = self.status.get_first(role='ucsm', parameter='host_list')
                network_node_host = self.status.get_first(role='ucsm', parameter='network_node_host')
                #ucsm_service_profile = 'test-profile'
                #ucsm(host=ucsm_ip, username=ucsm_user, password=ucsm_password, service_profile_name=ucsm_service_profile)
                conf_as_string = conf_as_string.replace('{ucsm_ip}', ucsm_ip)
                conf_as_string = conf_as_string.replace('{ucsm_username}', ucsm_user)
                conf_as_string = conf_as_string.replace('{ucsm_password}', ucsm_password)
                #l_hostnames = self.status.get(role='compute', parameter='hostname') + self.status.get(role='controller', parameter='hostname')
                conf_as_string = conf_as_string.replace('{ucsm_host_list}', ucsm_host_list)
                conf_as_string = conf_as_string.replace('{network_node_host}', network_node_host)
        log.info(msg='Config for OS deployer:\n' + conf_as_string)
        return conf_as_string
Exemplo n.º 2
0
    def create_paas(self, phase):
        log.info('\n\nStarting {0} phase'.format(phase))
        paas_phase = self.topology.get(phase, [])
        if not paas_phase:
            log.info('Nothing defined in {0} section'.format(phase))
            return

        for segment in paas_phase:
            # possible values: net, mac, ip, hostname, user, password, cmd.
            segment.update({key: segment.get(key, 'Unknown_' + key).format(lab_id=self.lab_id)
                            for key in ['hostname', 'net', 'mac', 'ip', 'host_list', 'network_node_host'] if not segment.get(key)})
            segment['user'] = segment.get('user', 'ubuntu')
            segment['password'] = segment.get('password', 'ubuntu')
            segment['role'] = segment['hostname'].split('-')[-1]
            commands = segment['cmd']

            if not segment['hostname'].startswith('Unknown'):
                if segment['ip'].startswith('Unknown'):
                    ip = self.status.hostname_2_ip[segment['hostname']]
                else:
                    ip = segment['ip']
            elif not segment['mac'].startswith('Unknown'):
                ip = self.status.mac_2_ip[segment['mac']]
            elif segment['net'].startswith('local'):
                ip = '127.0.0.1'
            elif segment['net'].startswith('2001:'):
                ip = lab.ip_for_mac_and_prefix(segment['mac'], prefix=segment['net'])
            else:
                raise exceptions.UserWarning('no way to determine where to execute! you provided hostname={hostname} net={net} mac={mac}')

            for cmd in commands:
                cmd = cmd.format(lab_id=self.lab_id)
                if ip in ['localhost', '127.0.0.1']:
                    local(cmd)
                else:
                    with settings(host_string='{user}@{ip}'.format(user=segment['user'], ip=ip), password=segment['password'], connection_attempts=50, warn_only=False):
                        if cmd.startswith('deploy_devstack'):
                            self.deploy_by_devstack(cmd)
                        elif cmd.startswith('deploy_by_packstack'):
                            self.deploy_by_packstack(cmd=cmd)
                        elif cmd.startswith('deploy_dibbler'):
                            self.deploy_dibbler(cmd)
                        elif cmd.startswith('put_config'):
                            self.put_config(cmd)
                        elif cmd.startswith('get_artifact'):
                            self.get_artifact(cmd)
                        elif cmd.startswith('run_tempest'):
                            self.run_tempest(cmd)
                        elif cmd.startswith('run_neutron_api_tests'):
                            self.run_neutron_api_tests()
                        elif cmd.startswith('register_as'):
                            self.status.set(role=segment['role'], ip=segment['ip'],
                                            mac=segment['mac'], hostname=segment['hostname'],
                                            user=segment['user'], password=segment['password'],
                                            host_list=segment['host_list'],
                                            network_node_host=segment['network_node_host'])
                        else:
                            sudo(cmd)
Exemplo n.º 3
0
 def create_networks(self):
     log.info('\n\nStarting IaaS phase- creating nets')
     for network_template in self.topology['networks']:
         xml = network_template.format(lab_id=self.lab_id)
         if not self.is_only_xml:
             net = _conn().networkDefineXML(xml)
             net.create()
             net.setAutostart(True)
         self.save_xml(name=self.search_for(self.name_re, xml), xml=xml)
Exemplo n.º 4
0
 def create_networks(self):
     log.info('\n\nStarting IaaS phase- creating nets')
     for network_template in self.topology['networks']:
         xml = network_template.format(lab_id=self.lab_id)
         if not self.is_only_xml:
             net = _conn().networkDefineXML(xml)
             net.create()
             net.setAutostart(True)
         self.save_xml(name=self.search_for(self.name_re, xml), xml=xml)
Exemplo n.º 5
0
 def delete_of_something(self, list_of_something):
     for something in list_of_something():
         if 'lab-{0}'.format(self.lab_id) in something.name():
             try:
                 something.destroy()
             except libvirt.libvirtError:
                 print >> sys.stderr, '{0} is not active, undefining...'.format(something.name())
             something.undefine()
             log.info('{0} was deleted'.format(something.name()))
Exemplo n.º 6
0
 def delete_of_something(self, list_of_something):
     for something in list_of_something():
         if 'lab-{0}'.format(self.lab_id) in something.name():
             try:
                 something.destroy()
             except libvirt.libvirtError:
                 print >> sys.stderr, '{0} is not active, undefining...'.format(
                     something.name())
             something.undefine()
             log.info('{0} was deleted'.format(something.name()))
Exemplo n.º 7
0
 def run_pre_or_post(self, pre_or_post):
     log.info('\n\nStarting {0} phase'.format(pre_or_post))
     list_of_commands = self.topology.get(pre_or_post, [])
     if not list_of_commands:
         log.info('Nothing defined in {0} section'.format(pre_or_post))
         return
     else:
         for cmd in list_of_commands:
             if cmd.startswith('run_tempest_local'):
                 self.run_tempest_local()
             else:
                 local(cmd.format(lab_id=self.lab_id))
Exemplo n.º 8
0
    def create_domains(self):
        log.info('\n\nStarting IaaS phase- creating VMs')
        for domain_template in self.topology['servers']:
            image_url = self.search_for(self.image_url_re, domain_template)
            domain_name = self.search_for(self.name_re, domain_template)

            image_local, kernel_local = self.wget_image(local_dir=lab.DISKS_DIR, image_url=image_url)
            disk_local, cloud_init_local = self.create_disk(image_local, domain_name)
            xml = domain_template.format(lab_id=self.lab_id, disk=disk_local, kernel=kernel_local, disk_cloud_init=cloud_init_local)
            if not self.is_only_xml:
                domain = _conn().defineXML(xml)
                domain.create()
            self.save_xml(name=domain_name, xml=xml)
Exemplo n.º 9
0
    def create_paas(self):
        log.info('\n\nStarting PAAS phase')
        for net_mac_cmd in self.topology['paas']:
            net = net_mac_cmd['net'].format(lab_id=self.lab_id)
            mac = net_mac_cmd['mac'].format(lab_id=self.lab_id)
            cmd = net_mac_cmd['cmd'].format(lab_id=self.lab_id)

            if net == 'local':
                local(cmd)
            else:
                ip = self.ip_for_mac(net=net, mac=mac)
                with settings(host_string='ubuntu@' + ip):
                    sudo(cmd)
Exemplo n.º 10
0
    def create_paas(self):
        log.info('\n\nStarting PAAS phase')
        for net_mac_cmd in self.topology['paas']:
            net = net_mac_cmd['net'].format(lab_id=self.lab_id)
            mac = net_mac_cmd['mac'].format(lab_id=self.lab_id)
            cmd = net_mac_cmd['cmd'].format(lab_id=self.lab_id)

            if net == 'local':
                local(cmd)
            else:
                ip = self.ip_for_mac(net=net, mac=mac)
                with settings(host_string='ubuntu@' + ip):
                    sudo(cmd)
Exemplo n.º 11
0
 def log(self):
     log.info('\n\n Report on lab: ' + str(self.lab_id))
     for hostname in sorted(self.hostname_2_ip.keys()):
         log.info(hostname + ': ' + self.hostname_2_ip[hostname])
     log.info('\n')
     for role in sorted(self.info.keys()):
         log.info(role + ' ip: ' + ' '.join(self.get(role=role, parameter='ip')))
Exemplo n.º 12
0
    def create_domains(self):
        log.info('\n\nStarting IaaS phase- creating VMs')
        for domain_template in self.topology['servers']:
            image_url = self.search_for(self.image_url_re, domain_template)
            domain_name = self.search_for(self.name_re, domain_template)

            image_local, kernel_local = self.wget_image(
                local_dir=lab.DISKS_DIR, image_url=image_url)
            disk_local, cloud_init_local = self.create_disk(
                image_local, domain_name)
            xml = domain_template.format(lab_id=self.lab_id,
                                         disk=disk_local,
                                         kernel=kernel_local,
                                         disk_cloud_init=cloud_init_local)
            if not self.is_only_xml:
                domain = _conn().defineXML(xml)
                domain.create()
            self.save_xml(name=domain_name, xml=xml)
Exemplo n.º 13
0
def venv(private=False):
    log.info("Installing packages from requirements")
    # local("sudo apt-get install -y $(cat requirements_packages)")
    venv_path = CVENV
    if private:
        venv_path = LVENV
    if not os.path.exists(venv_path):
        log.info("Creating virtual environment in {dir}".format(dir=venv_path))
        local("virtualenv --setuptools %s" % venv_path)
    else:
        log.info("Virtual environment in {dir} already exists".format(dir=venv_path))
Exemplo n.º 14
0
def venv(private=False):
    log.info("Installing packages from requirements")
    # local("sudo apt-get install -y $(cat requirements_packages)")
    venv_path = CVENV
    if private:
        venv_path = LVENV
    if not os.path.exists(venv_path):
        log.info("Creating virtual environment in {dir}".format(dir=venv_path))
        local("virtualenv --setuptools %s" % venv_path)
    else:
        log.info("Virtual environment in {dir} already exists".format(dir=venv_path))
Exemplo n.º 15
0
    def create_networks(self):
        from bs4 import BeautifulSoup

        log.info('\n\nStarting IaaS phase- creating nets')
        list_of_networks = self.topology.get('networks', [])
        if not list_of_networks:
            log.info('Nothing defined in networks section')
            return

        for network_template in self.topology['networks']:
            if 'ipv6_prefix' in network_template:
                xml = network_template.format(lab_id=self.lab_id, ipv6_prefix=self.define_ipv6_prefix())
            else:
                xml = network_template.format(lab_id=self.lab_id)
            b = BeautifulSoup(xml, 'lxml')
            net_name = b.find('name').string
            self.save_xml(name='net-' + net_name, xml=xml)
            if not self.is_only_xml:
                net = _conn().networkDefineXML(xml)
                net.create()
                net.setAutostart(True)
                log.info('Network {} created'.format(net_name))
Exemplo n.º 16
0
    def create_domains(self):
        from bs4 import BeautifulSoup

        log.info('\n\nStarting IaaS phase- creating VMs')
        list_of_domains = self.topology.get('servers', [])
        if not list_of_domains:
            log.info('Nothing defined in servers section')
            return

        for domain_template in self.topology['servers']:
            b = BeautifulSoup(domain_template, 'lxml')

            hostname = b.find('name').string.format(lab_id=self.lab_id)
            host_type = hostname.split('-')[-1]
            # todo kshileev - what if we have two mac adresses
            # and only second one is for ip resolving is needed?
            mac = b.find('mac')['address'].format(lab_id=self.lab_id)
            image_url = b.find(string=re.compile('^http'))

            image_path = lab.wget_file(local_dir=lab.IMAGES_DIR, file_url=image_url)
            main_disk_path = self.create_main_disk(image_path=image_path, hostname=hostname, is_no_backing='disk_no_backing' in domain_template)

            if 'disk_cloud_init' in domain_template:
                cloud_init_disk_path = self.create_cloud_init_disk(hostname=hostname)
            else:
                cloud_init_disk_path = 'NoCloudInitDiskRequested'

            xml = domain_template.format(lab_id=self.lab_id,
                                         disk=main_disk_path,
                                         disk_no_backing=main_disk_path,
                                         disk_cloud_init=cloud_init_disk_path)
            self.save_xml(name=hostname, xml=xml)
            if not self.is_only_xml:
                domain = _conn().defineXML(xml)
                domain.create()
                net = b.find('interface').find('source')['network'].format(lab_id=self.lab_id)
                ip = lab.ip_for_mac_by_looking_at_libvirt_leases(net=net, mac=mac)
                self.status.set(role=host_type, ip=ip, mac=mac, hostname=hostname)
                log.info(msg='Domain {0} created'.format(hostname))
Exemplo n.º 17
0
def requirements():
    log.info("Installing python modules from requirements")
    local("pip install -Ur requirements")
Exemplo n.º 18
0
def test():
    """ For testing purposes only """
    log.info("Testing something")
    a = local("which python")
    print a.real_command
Exemplo n.º 19
0
def destroy():
    """ Destroying all lab machines and networks """
    log.info("Destroying lab {lab}".format(lab=LAB))
    local("python ./tools/cloud/create.py -l {lab} -x".format(lab=LAB))
Exemplo n.º 20
0
def requirements():
    log.info("Installing python modules from requirements")
    local("pip install -Ur requirements")
Exemplo n.º 21
0
def destroy():
    """ Destroying all lab machines and networks """
    log.info("Destroying lab {lab}".format(lab=LAB))
    local("python ./tools/cloud/create.py -l {lab} -x".format(lab=LAB))