Пример #1
0
    def build(self, build_args):
        show('Building:')
        show.tab()

        if build_args[0] == 'patch':
            show('Syncing the patches:')
            # TODO: make this generic
            #util.run(['rsync', '-rc', '--delete', '/home/tbabej/Work/patches',
            #          '%s:dev/' % self.ip])

            for patch_id in build_args[1:]:
                show('Applying patch {patch}'.format(patch=patch_id))
                self.cmd("bash labtool/ipa-fun-apply-patch.sh"
                         " {patch} {log}".format(patch=patch_id,
                                                 **self.locals))

        elif build_args[0] == 'branch':
            show('Checking out to {branch}'.format(branch=build_args[1]))
            self.cmd("bash labtool/ipa-fun-checkout.sh"
                     " {branch} {log}".format(branch=build_args[1],
                                              **self.locals))
        else:
            raise RuntimeError("Unknown action: %s" % build_args[0])

        show('Installing build dependencies')
        self.install_build_dependencies()

        show('Applying build workarounds')
        self.apply_build_workarounds()

        show('Building sources')
        self.cmd("bash labtool/ipa-fun-build.sh"
                 " {log}".format(**self.locals))

        show.untab()
Пример #2
0
    def build(self, build_args):
        show('Building:')
        show.tab()

        if build_args[0] == 'patch':
            show('Syncing the patches:')
            # TODO: make this generic
            #util.run(['rsync', '-rc', '--delete', '/home/tbabej/Work/patches',
            #          '%s:dev/' % self.ip])

            for patch_id in build_args[1:]:
                show('Applying patch {patch}'.format(patch=patch_id))
                self.cmd("bash labtool/ipa-fun-apply-patch.sh"
                         " {patch} {log}".format(patch=patch_id,
                                                 **self.locals))

        elif build_args[0] == 'branch':
            show('Checking out to {branch}'.format(branch=build_args[1]))
            self.cmd("bash labtool/ipa-fun-checkout.sh"
                     " {branch} {log}".format(branch=build_args[1],
                                              **self.locals))
        else:
            raise RuntimeError("Unknown action: %s" % build_args[0])

        show('Installing build dependencies')
        self.install_build_dependencies()

        show('Applying build workarounds')
        self.apply_build_workarounds()

        show('Building sources')
        self.cmd("bash labtool/ipa-fun-build.sh"
                 " {log}".format(**self.locals))

        show.untab()
Пример #3
0
    def make_snapshot(self, name):
        show("Deleting all previous snapshots")
        show.tab()

        self.shutdown(name)

        for snap in self.api.vms.get(name).snapshots.list():
            if snap.get_description() != 'Active VM':
                show("Deleting snapshot: %s" % snap.get_description())
                snap.delete()

        while len(self.api.vms.get(name).snapshots.list()) > 1:
            show("Waiting for the deletion to complete.")
            sleep(5)

        show.untab()

        try:
            snapshot = params.Snapshot(description=locals.SNAPSHOT_NAME,
                                       vm=self.api.vms.get(name))
            self.api.vms.get(name).snapshots.add(snapshot)
            show("Creating a Snapshot")
            show('Waiting for Snapshot creation to finish')
            while self.api.vms.get(name).status.state == 'image_locked':
                sleep(5)
        except Exception as e:
            show('Failed to Create a Snapshot:\n%s' % str(e))

        if self.get_snapshot(name, locals.SNAPSHOT_NAME):
            show("Snapshot created: %s" % locals.SNAPSHOT_NAME)

        sleep(15)
        show.untab()
Пример #4
0
    def make_snapshot(self, name):
        show("Deleting all previous snapshots")
        show.tab()

        self.shutdown(name)

        for snap in self.get_vm(name).snapshots.list():
            if snap.get_description() != 'Active VM':
                show("Deleting snapshot: %s" % snap.get_description())
                snap.delete()

        while len(self.get_vm(name).snapshots.list()) > 1:
            show("Waiting for the deletion to complete.")
            sleep(15)

        show.untab()

        try:
            snapshot = params.Snapshot(description=locals.SNAPSHOT_NAME,
                                       vm=self.get_vm(name))
            self.get_vm(name).snapshots.add(snapshot)
            show("Creating a Snapshot")
            show('Waiting for Snapshot creation to finish')
            while self.get_vm(name).status.state == 'image_locked':
                sleep(15)
        except Exception as e:
            show('Failed to Create a Snapshot:\n%s' % str(e))

        if self.get_snapshot(name, locals.SNAPSHOT_NAME):
            show("Snapshot created: %s" % locals.SNAPSHOT_NAME)

        show.untab()
Пример #5
0
    def create_vm(self,
                  name,
                  memory=locals.MEMORY,
                  template=locals.TEMPLATE_NAME):
        """Creates a VM from given parameters and returns its hostname."""

        show('VM creation:')
        show.tab()
        show('Name: %s' % name)
        show('Template: %s' % template)
        show('Memory: %s' % memory)

        tmpl = self.api.templates.get(template)
        if not tmpl:
            raise ValueError('Template does not exist: %s' % template)

        # # Check whether the template exist, if so, create the VM
        # if util.get_latest_template(self.api, template) is None:
        #     raise ValueError('Template does not exist: %s' % template)

        # Set VM's parameters as defined in locals.py
        pars = params.VM(name=name,
                         memory=memory,
                         cluster=self.api.clusters.get(self.cluster),
                         template=tmpl)

        # locals.HOST can be used to enforce usage of a particular host
        if locals.HOST:
            pars.set_placement_policy(
                params.VmPlacementPolicy(host=self.api.hosts.get(locals.HOST),
                                         affinity='pinned'))

        vm = self.api.vms.add(pars)
        show('VM was created from Template successfully')

        # Set corret permissions so that VM can be seen in WebAdmin
        if not self.kerberos:
            admin_vm_manager_perm = params.Permission(
                role=self.api.roles.get('UserVmManager'),
                user=self.api.users.get('admin'))

            vm.permissions.add(admin_vm_manager_perm)
            show('Permissions for admin to see VM set')

        # VM automatically shuts down after creation
        show('Waiting for VM to reach Down status')
        while self.get_vm_state(name, vm) != 'down':
            vm = self.get_vm(name)
            sleep(15)
        show.untab()
        return vm
Пример #6
0
    def create_vm(self, name, memory=locals.MEMORY,
                  template=locals.TEMPLATE_NAME):
        """Creates a VM from given parameters and returns its hostname."""

        show('VM creation:')
        show.tab()
        show('Name: %s' % name)
        show('Template: %s' % template)
        show('Memory: %s' % memory)

        tmpl = self.api.templates.get(template)
        if not tmpl:
            raise ValueError('Template does not exist: %s' % template)

        # # Check whether the template exist, if so, create the VM
        # if util.get_latest_template(self.api, template) is None:
        #     raise ValueError('Template does not exist: %s' % template)

        # Set VM's parameters as defined in locals.py
        pars = params.VM(name=name,
                         memory=memory,
                         cluster=self.api.clusters.get(self.cluster),
                         template=tmpl)

        # locals.HOST can be used to enforce usage of a particular host
        if locals.HOST:
            pars.set_placement_policy(params.VmPlacementPolicy(
                                         host=self.api.hosts.get(locals.HOST),
                                         affinity='pinned'))


        vm = self.api.vms.add(pars)
        show('VM was created from Template successfully')

        # Set corret permissions so that VM can be seen in WebAdmin
        if not self.kerberos:
            admin_vm_manager_perm = params.Permission(
                                        role=self.api.roles.get('UserVmManager'),
                                        user=self.api.users.get('admin'))

            vm.permissions.add(admin_vm_manager_perm)
            show('Permissions for admin to see VM set')

        # VM automatically shuts down after creation
        show('Waiting for VM to reach Down status')
        while self.get_vm_state(name, vm) != 'down':
            vm = self.get_vm(name)
            sleep(2)
        show.untab()
        return vm
Пример #7
0
    def revert_to_snapshot(self, name):
        show.tab()

        self.stop(name)

        show('Restoring the snapshot: %s' % locals.SNAPSHOT_NAME)
        snapshot = self.get_snapshot(name, locals.SNAPSHOT_NAME)
        if not snapshot:
            raise ValueError("Snapshot %s does not exist"
                             % locals.SNAPSHOT_NAME)

        snapshot.restore()

        # VM automatically shuts down after creation
        show('Waiting for VM to reach Down status')
        while self.get_vm(name).status.state != 'down':
            sleep(15)
        show.untab()
        return self.load_vm(name)
Пример #8
0
    def revert_to_snapshot(self, name):
        show.tab()

        self.stop(name)

        show('Restoring the snapshot: %s' % locals.SNAPSHOT_NAME)
        snapshot = self.get_snapshot(name, locals.SNAPSHOT_NAME)
        if not snapshot:
            raise ValueError("Snapshot %s does not exist"
                             % locals.SNAPSHOT_NAME)

        snapshot.restore()

        # VM automatically shuts down after creation
        show('Waiting for VM to reach Down status')
        while self.api.vms.get(name).status.state != 'down':
            sleep(1)

        return self.load_vm(name)
Пример #9
0
    def run_tests(self):
        show('Testing:')
        show.tab()

        # run the test suite
        show('Configuring VM for tests')
        self.cmd("bash labtool/ipa-fun-setup-tests.sh"
                 " {log}".format(**self.locals))

        show('Running whole test suite')
        ret = self.cmd("bash labtool/ipa-fun-run-tests.sh"
                       " {log}".format(**self.locals),
           allow_failure=True)

        if ret == 0:
            show('PASSED. See {log} for the logs.'.format(**self.locals))
        else:
            show('FAILED. See {log} for the logs.'.format(**self.locals))

        show.untab()
Пример #10
0
    def revert_to_snapshot(self, name):
        show.tab()

        if len(self.get_domain(name).listAllSnapshots()) != 1:
            raise RuntimeError("Incorrect number of snapshots for %s" % name)

        show('Correct number of snapshots for %s' % name)

        snapshot = self.get_domain(name).listAllSnapshots()[0].getName()

        stdout, stderr, rc = util.run([
            'virsh', 'snapshot-revert', '--domain', name, '--snapshotname',
            snapshot, '--force'
        ])

        if rc != 0:
            raise RuntimeError("Could not revert to snapshot for %s" % name)

        show('Revert successful')
        show.untab()
Пример #11
0
    def run_tests(self):
        show('Testing:')
        show.tab()

        # run the test suite
        show('Configuring VM for tests')
        self.cmd("bash labtool/ipa-fun-setup-tests.sh"
                 " {log}".format(**self.locals))

        show('Running whole test suite')
        ret = self.cmd("bash labtool/ipa-fun-run-tests.sh"
                       " {log}".format(**self.locals),
                       allow_failure=True)

        if ret == 0:
            show('PASSED. See {log} for the logs.'.format(**self.locals))
        else:
            show('FAILED. See {log} for the logs.'.format(**self.locals))

        show.untab()
Пример #12
0
    def remove_vm(self, name):
        show('Removing the VM:')
        show.tab()

        vm = self.api.vms.get(name)
        if vm is None:
            show('Could not obtain VM. Probably does not exist.')
            return

        try:
            vm.stop()
            show('Waiting for VM to reach Down status')
        except Exception:
            show('Vm is not running.')
            pass

        while self.api.vms.get(name).status.state != 'down':
            sleep(1)

        vm.delete()
        show('{name} was removed.'.format(name=name))
        show.untab()
Пример #13
0
    def reboot(self, name):
        show('Rebooting the VM:')
        show.tab()

        vm = self.api.vms.get(name)
        vm.shutdown()

        show('Waiting for VM to reach Down status')
        while self.api.vms.get(name).status.state != 'down':
            sleep(1)

        if self.api.vms.get(name).status.state != 'up':
            show('Starting VM')
            vm.start()
            show('Waiting for VM to reach Up status')
            while self.api.vms.get(name).status.state != 'up':
                sleep(1)

        show('Waiting for all the services to start')
        sleep(60)

        show.untab()
Пример #14
0
    def reboot(self, name):
        show('Rebooting the VM:')
        show.tab()

        vm = self.get_vm(name)
        vm.shutdown()

        show('Waiting for VM to reach Down status')
        while self.get_vm_state(name, vm) != 'down':
            vm = self.get_vm(name)
            sleep(15)

        if self.get_vm_state(name, vm) != 'up':
            show('Starting VM')
            vm.start()
            show('Waiting for VM to reach Up status')
            while self.get_vm_state(name) != 'up':
                sleep(15)

        show('Waiting for all the services to start')
        sleep(60)

        show.untab()
Пример #15
0
    def reboot(self, name):
        show('Rebooting the VM:')
        show.tab()

        vm = self.get_vm(name)
        vm.shutdown()

        show('Waiting for VM to reach Down status')
        while self.get_vm_state(name, vm) != 'down':
            vm = self.get_vm(name)
            sleep(15)

        if self.get_vm_state(name, vm) != 'up':
            show('Starting VM')
            vm.start()
            show('Waiting for VM to reach Up status')
            while self.get_vm_state(name) != 'up':
                sleep(15)

        show('Waiting for all the services to start')
        sleep(60)

        show.untab()
Пример #16
0
    def remove_vm(self, name):
        show('Removing the VM:')
        show.tab()

        try:
            vm = self.get_vm(name)
        except ValueError:
            show('Could not obtain VM. Probably does not exist.')
            return

        try:
            vm.stop()
            show('Waiting for VM to reach Down status')
        except Exception:
            show('Vm is not running.')
            pass

        while self.get_vm_state(name) != 'down':
            sleep(10)

        vm.delete()
        show('{name} was removed.'.format(name=name))
        show.untab()
Пример #17
0
    def revert_to_snapshot(self, name):
        show.tab()

        if len(self.get_domain(name).listAllSnapshots()) != 1:
            raise RuntimeError("Incorrect number of snapshots for %s" % name)

        show('Correct number of snapshots for %s' % name)

        snapshot = self.get_domain(name).listAllSnapshots()[0].getName()

        stdout, stderr, rc = util.run(['virsh',
                                       'snapshot-revert',
                                       '--domain',
                                       name,
                                       '--snapshotname',
                                       snapshot,
                                       '--force'
                                     ])

        if rc != 0:
            raise RuntimeError("Could not revert to snapshot for %s" % name)

        show('Revert successful')
        show.untab()
Пример #18
0
    # Setup a new hostname
    vm.set_hostname(trust=args.trust)

    if args.install:
        show('Preparing:')

        # Installs FreeIPA packages either from local source or from repository
        vm.install_packages(args.install)

        if args.install[0] == 'ipa':
            vm.prepare_install(args.firewall, args.selinux, args.trust)
            show.untab()
            vm.install_ipa()

            show('Post-install configuration:')
            show.tab()
            vm.check_services()
            show.untab()

            if args.test:
                vm.run_tests()

            if args.trust:
                vm.setup_trust()

    show.untab()

################### Replicas and clients untested and not working ATM #########
    if args.replicas:
        replicas = []
Пример #19
0
def main(args):
    show('***** Welcome to LabTool *****')
    show('')

    if locals.REQUIRE_ROOT:
        util.require_root()

    BackendClass = getattr(backends, locals.BACKEND)

    show('Estabilishing connection to %s lab' % locals.BACKEND)

    backend = BackendClass(url=locals.URL,
                           username=locals.USERNAME,
                           password=locals.PASSWORD,
                           cluster_name=locals.CLUSTER_NAME,
                           ca_file=locals.CA_FILE)

    # We need to remove the VM before running check_arguments()
    #if args.remove:
    #    backend.remove_vm(args.name)

    #if not args.local:
    #    backend.check_arguments(args.name, args.template, args.connect)

    #show.untab()

    show('Setting up: %s' % args.name)
    show.tab()

    #elif args.local:
    #    hostname = args.name.split('.')[0]
    #    locals.DOMAIN = 'ipa.com'
    #else:

    if backend.exists(args.name) and not args.connect:
        show('VM exists, reverting back to snapshot')
        try:
            backend.revert_to_snapshot(args.name)
        except ValueError as e:
            if args.remove:
                show(str(e) + ': removing the whole VM')
                backend.remove_vm(args.name)
            else:
                raise Exception(
                    str(e) + ': use --remove if you want '
                    'to remove whole VM')

    if not backend.exists(args.name):
        if args.connect:
            raise Exception(
                "You requested --connect but specified VM does not "
                "exist, exiting.")

        vm = backend.create_vm(args.name,
                               template=args.template or locals.TEMPLATE_NAME)
    else:
        vm = backend.load_vm(args.name)

    vm.connect()
    vm.setup_logging_path()

    monitor(vm.hostname, vm.domain)

    if args.workspace or not vm.detect_workspace():
        vm.create_workspace()
    vm.update_workspace()

    backend.make_snapshot(args.name)
    while True:
        try:
            vm.start()
            break
        except Exception, e:
            # vm.start() can fail if disks are not in state 'down'
            show("Skipping error %s" % str(e))
            time.sleep(5)
            pass
Пример #20
0
    # Setup a new hostname
    vm.set_hostname(trust=args.trust)

    if args.install:
        show('Preparing:')

        # Installs FreeIPA packages either from local source or from repository
        vm.install_packages(args.install)

        if args.install[0] == 'ipa':
            vm.prepare_install(args.firewall, args.selinux, args.trust)
            show.untab()
            vm.install_ipa()

            show('Post-install configuration:')
            show.tab()
            vm.check_services()
            show.untab()

            if args.test:
                vm.run_tests()

            if args.trust:
                vm.setup_trust()

    show.untab()

    ################### Replicas and clients untested and not working ATM #########
    if args.replicas:
        replicas = []
Пример #21
0
def main(args):
    show('***** Welcome to LabTool *****')
    show('')

    if locals.REQUIRE_ROOT:
        util.require_root()

    BackendClass = getattr(backends, locals.BACKEND)

    show('Estabilishing connection to %s lab' % locals.BACKEND)

    backend = BackendClass(url=locals.URL,
                           username=locals.USERNAME,
                           password=locals.PASSWORD,
                           cluster_name=locals.CLUSTER_NAME,
                           ca_file=locals.CA_FILE)

    # We need to remove the VM before running check_arguments()
    #if args.remove:
    #    backend.remove_vm(args.name)

    #if not args.local:
    #    backend.check_arguments(args.name, args.template, args.connect)

    #show.untab()

    show('Setting up: %s' % args.name)
    show.tab()

    #elif args.local:
    #    hostname = args.name.split('.')[0]
    #    locals.DOMAIN = 'ipa.com'
    #else:

    if backend.exists(args.name) and not args.connect:
        show('VM exists, reverting back to snapshot')
        try:
            backend.revert_to_snapshot(args.name)
        except ValueError as e:
            if args.remove:
                show(str(e) + ': removing the whole VM')
                backend.remove_vm(args.name)
            else:
                raise Exception(str(e) + ': use --remove if you want '
                                'to remove whole VM')

    if not backend.exists(args.name):
        if args.connect:
            raise Exception("You requested --connect but specified VM does not "
                            "exist, exiting.")

        vm = backend.create_vm(args.name,
                               template=args.template or locals.TEMPLATE_NAME)
    else:
        vm = backend.load_vm(args.name)

    vm.connect()
    vm.setup_logging_path()

    monitor(vm.hostname, vm.domain)

    if args.workspace or not vm.detect_workspace():
        vm.create_workspace()
    vm.update_workspace()

    backend.make_snapshot(args.name)
    while True:
        try:
            vm.start()
            break
        except Exception, e:
            # vm.start() can fail if disks are not in state 'down'
            show("Skipping error %s" % str(e))
            time.sleep(5)
            pass