Build the Undercloud by using instack-virt-setup script.

def build_undercloud_on_libvirt(self, image_path,
                                    rhsm=None, repositories=[]):
        """Build the Undercloud by using instack-virt-setup script."""
        self.run('sysctl net.ipv4.ip_forward=1')
        self.fetch_image(path=image_path, dest='/home/stack/guest_image.qcow2',
                         user='stack')
        # NOTE(Gonéri): this is a hack for our OpenStack, the MTU of its outgoing route
        # is 1400 and libvirt do not provide a mechanism to adjust the guests MTU.
        self.run("LIBGUESTFS_BACKEND=direct virt-customize -a /home/stack/guest_image.qcow2 --run-command 'echo MTU=\"1400\" >> /etc/sysconfig/network-scripts/ifcfg-eth0'")

        env = Environment()
        env.loader = FileSystemLoader(pkg_data_filename('template'))
        template = env.get_template('virt-setup-env.j2')
        self.run('mkdir -p /home/stack/DIB', user='stack')
        self.run('cp -v /etc/yum.repos.d/*.repo /home/stack/DIB', user='stack')
        # NOTE(Gonéri): Hack to be sure DIB won't complain because of missing gpg files
        # self.run('sed -i "s,gpgcheck=1,gpgcheck=0," /home/stack/DIB/*.repo', user='stack')
        dib_yum_repo_conf = self.run('find /home/stack/DIB -type f', user='stack')[0].split()
        virt_setup_template = {
            'dib_yum_repo_conf': dib_yum_repo_conf,
            'node': {
                'count': 2,
                'mem': 6144,
                'cpu': 2
            },
            'undercloud_node_mem': 8192,
            'guest_image_name': '/home/stack/guest_image.qcow2'
        }

        if rhsm is not None:
            virt_setup_template['rhsm'] = {
                'login': rhsm.get('login'),
                'password': rhsm.get('password', os.environ.get('RHN_PW')),
                'pool_id': rhsm.get('pool_id', ''),
                'repositories': [i['name'] for i in repositories if i['type'] == 'rhsm_channel']
            }
        virt_setup_env = template.render(virt_setup_template)
        self.create_file('virt-setup-env', virt_setup_env, user='stack')
        self.run('virsh destroy instack', ignore_error=True)
        self.run('virsh undefine instack --remove-all-storage', ignore_error=True)
        self.run('source virt-setup-env; instack-virt-setup', user='stack')
        undercloud_ip = self.run(
            '/sbin/ip n | grep $(tripleo get-vm-mac instack) | awk \'{print $1;}\'',
            user='stack')[0]
        assert undercloud_ip, 'undercloud should have an IP'
        undercloud = Undercloud(hostname=undercloud_ip,
                                via_ip=self.hostname,
                                user='root',
                                key_filename=self._key_filename)
        return undercloud