Ejemplo n.º 1
0
def standalone_environment_setup():
    """
    This is intended for Nose environment (standalone).
    """
    helpers.bigrobot_nose_setup("True")
    big_setup(is_gobot='False', auto_package_install=False)
    os.environ["AUTOBOT_LOG"] = helpers.bigrobot_log_path_exec_instance(
    ) + "/debug.log"
    print()
Ejemplo n.º 2
0
import os
import sys
import robot

# Special settings for the task server, not intended for execution on client.
if ('BIGROBOT_ESB' in os.environ
        and os.environ['BIGROBOT_ESB'].lower() == 'true'):
    bigrobot_path = os.path.dirname(__file__) + '/../..'
    sys.path.insert(0, bigrobot_path + '/vendors/exscript/src')
    # sys.path.insert(0, bigrobot_path + '/vendors/paramiko')
    sys.path.insert(0, bigrobot_path + '/esb')
    sys.path.insert(0, bigrobot_path)

    import autobot.helpers as helpers
    helpers.set_env('IS_GOBOT', 'False')
    helpers.bigrobot_path(bigrobot_path)
    helpers.bigrobot_log_path('/tmp/bigrobot_esb_log')
    helpers.bigrobot_log_path_exec_instance(
        helpers.bigrobot_log_path() + "/" +
        os.path.dirname(__file__).split('/')[-1])
    helpers.set_env(
        'AUTOBOT_LOG',
        helpers.bigrobot_log_path_exec_instance() + "/bigrobot_autobot.log")
Ejemplo n.º 3
0
import autobot.setup_env as setup_env
from autobot.nose_support import run, log_to_console, sleep, Singleton
from keywords.BsnCommon import BsnCommon
from keywords.T5Torture import T5Torture

helpers.set_env('BIGROBOT_TEST_POSTMORTEM', 'False', quiet=True)
helpers.set_env('BIGROBOT_TEST_SETUP', 'False', quiet=True)
helpers.set_env('BIGROBOT_TEST_CLEAN_CONFIG', 'False', quiet=True)
helpers.set_env('BIGROBOT_TEST_TEARDOWN', 'False', quiet=True)
helpers.remove_env('BIGROBOT_TOPOLOGY', quiet=True)
# Test suite is defined as the name of the test script minus its extension.
helpers.bigrobot_suite(os.path.basename(__file__).split('.')[0])
setup_env.standalone_environment_setup()

assert helpers.bigrobot_path() != None
assert helpers.bigrobot_log_path_exec_instance() != None
assert helpers.bigrobot_suite() != None
helpers.print_bigrobot_env(minimum=True)


class TestBcfEvents:
    __metaclass__ = Singleton

    def __init__(self):
        self.link_flap_sleep = BsnCommon().params_global('link_flap_sleep')
        self.in_event_sleep = BsnCommon().params_global('in_event_sleep')
        self.between_event_sleep = BsnCommon().params_global(
            'between_event_sleep')
        self.tflapnum = BsnCommon().params_global('tflapnum')
        self.vflapnum = BsnCommon().params_global('vflapnum')
        self.big_config_sleep = BsnCommon().params_global('big_config_sleep')
Ejemplo n.º 4
0
def bigrobot_env_init(is_gobot='True'):
    os.environ['IS_GOBOT'] = is_gobot

    helpers.bigrobot_log_path(default='.')
    if helpers.bigrobot_suite():
        _suite = helpers.bigrobot_suite()

        # If user specified full path, trim it down to just suite name. E.g.,
        # Change:
        #  /Users/vui/Documents/ws/myforks/bigrobot/testsuites_dev/vui/test_mininet
        # To:
        #  vui_test_mininet_20140513_095428
        _match = re.search(r'.+testsuites(_dev)?/(.+)$', _suite)
        if _match:
            _suite = re.sub(r'[\W\s]', '_', _match.group(2))
        helpers.bigrobot_log_path_exec_instance_relative(
            default="%s_%s" % (_suite, helpers.ts_local()))
    else:
        helpers.bigrobot_log_path_exec_instance_relative(
            default="<bigrobot_suite>")
    helpers.bigrobot_log_path_exec_instance(
        default="%s/%s" % (helpers.bigrobot_log_path(),
                           helpers.bigrobot_log_path_exec_instance_relative()))

    if helpers.bigrobot_suite():
        if helpers.bigrobot_topology() == None:
            _topo_p = helpers.bigrobot_suite() + ".physical.topo"
            _topo_v = helpers.bigrobot_suite() + ".virtual.topo"
            _topo_u = helpers.bigrobot_suite() + ".topo"  # p or v unspecified

            # There should exist a topo file for the test suite.
            if helpers.file_exists(_topo_p):
                topo_file = _topo_p
            elif helpers.file_exists(_topo_v):
                topo_file = _topo_v
            else:
                topo_file = _topo_u

            helpers.bigrobot_topology(default=topo_file)

        print("BigRobot suite: %s" % helpers.bigrobot_suite())
        print("BigRobot suite topology: %s" % helpers.bigrobot_topology())

    helpers.bigrobot_params(default='None')
    helpers.bigrobot_continuous_integration()
    helpers.bigrobot_exec_hint_format()
    helpers.bigrobot_log_archiver()
    helpers.bigrobot_debug(default=1)

    helpers.bigrobot_listener_log(
        default=(helpers.bigrobot_log_path_exec_instance() +
                 '/bigrobot_listener.log'))
    helpers.bigrobot_devcmd_log(
        default=(helpers.bigrobot_log_path_exec_instance() +
                 '/dev_commands.log'))
    if helpers.bigrobot_suite() is None:
        #!!! FIXME: need to handle None value..
        pass
    else:
        helpers.bigrobot_global_params(default=(helpers.bigrobot_suite() +
                                                '.params'))
    helpers.bigrobot_additional_params(
        default=(helpers.bigrobot_log_path_exec_instance() +
                 '/additional-params.topo'))

    helpers.bigrobot_path()
    # helpers.bigtest_path()
    helpers.python_path()
    helpers.bigrobot_test_setup()
    helpers.bigrobot_test_postmortem()
    helpers.bigrobot_test_clean_config()
    helpers.bigrobot_test_pause_on_fail()
    helpers.bigrobot_test_ztn()
    helpers.bigrobot_ignore_mininet_exception_on_close()
    helpers.bigrobot_preserve_mininet_screen_session_on_fail()
    helpers.bigrobot_esb()
    helpers.bigrobot_esb_broker()
    helpers.bigrobot_ztn_reload()
    helpers.bigrobot_ztn_installer()
    helpers.bigrobot_no_auto_reload()
    helpers.bigrobot_ha_logging()
    helpers.bigrobot_quiet_output()
    helpers.bigrobot_reconfig_reauth()
    helpers.bigrobot_selenium_browser()
    helpers.bigrobot_devconf_debug_level()
Ejemplo n.º 5
0
 def func():
     assert helpers.bigrobot_path() != None
     assert helpers.bigrobot_log_path_exec_instance() != None
     assert helpers.bigrobot_suite() != None
     helpers.print_bigrobot_env(minimum=True)
Ejemplo n.º 6
0
    def vm_setup(self, **kwargs):
        result = {
            "status_code": True,
            "status_descr": "Success",
        }

        try:
            vm_name = kwargs.get("vm_name", None)
            kvm_host = kwargs.get("kvm_host", KVM_SERVER)
            kvm_user = kwargs.get("kvm_user", KVM_USER)
            kvm_password = kwargs.get("kvm_password", KVM_PASSWORD)
            vm_host_name = kwargs.get("vm_host_name", None)
            vm_type = kwargs.get("vm_type", "bcf")
            qcow_path = kwargs.get("qcow_path", None)
            qcow_vm_path = None
            ip = kwargs.get("ip", None)
            vm_ram = kwargs.get("vm_ram", "2048")
            build_number = kwargs.get("build_number", None)
            if ip == 'None':
                ip = None
            cluster_ip = kwargs.get("cluster_ip", None)
            netmask = kwargs.get("netmask", "18")
            gateway = kwargs.get("gateway", "10.8.0.1")
            network_interface = kwargs.get("network_interface", "br0")
            self.log_path = LOG_BASE_PATH + '/' + vm_name
            try:
                if os.path.exists(self.log_path) or os.path.islink(
                        self.log_path):
                    pass
                else:
                    os.makedirs(self.log_path)
            except OSError as exc:  # Python >2.5
                if exc.errno == errno.EEXIST and os.path.isdir(LOG_BASE_PATH):
                    pass
                else:
                    # Last resort - put logs in /tmp
                    self.log_path = '/tmp' + '/' + vm_name
                    os.makedirs(self.log_path)

            # export IS_GOBOT="False"
            helpers.set_env("AUTOBOT_LOG",
                            "%s/%s.log" % (self.log_path, vm_name))
            helpers.bigrobot_log_path_exec_instance(self.log_path)

            # Note: helpers.summary_log() and helpers.log() are not called
            #       until after we've initialized the BigRobot log path
            #       (above). Don't attempt to write to logs before that
            #       or it will write logs to /tmp directory instead of the
            #       /tmp/<vm_name>/.
            helpers.summary_log("Creating VM with Name: %s " % vm_name)
            helpers.summary_log("Created log_path %s" % self.log_path)
            # remote_qcow_bvs_path = kwargs.get("remote_qcow_bvs_path", "/var/lib/jenkins/jobs/bvs\ master/lastSuccessful/archive/target/appliance/images/bcf/controller-bcf-2.0.8-SNAPSHOT.qcow2")
            remote_qcow_bvs_path = kwargs.get(
                "remote_qcow_bvs_path",
                "/var/lib/jenkins/jobs/bcf_master/lastSuccessful/archive/controller-bcf-*.qcow2"
            )
            remote_qcow_mininet_path = kwargs.get(
                "remote_qcow_mininet_path",
                "/var/lib/jenkins/jobs/t6-mininet-vm/builds/lastSuccessfulBuild/archive/t6-mininet-vm/ubuntu-kvm/t6-mininet.qcow2"
            )

            topo_file = self._create_temp_topo(kvm_host=kvm_host,
                                               vm_name=vm_name)
            # set the BIG ROBOT Topo file for console connections
            helpers.bigrobot_topology(topo_file)
            helpers.bigrobot_params("none")

            kvm_handle = self._connect_to_kvm_host(hostname=kvm_host,
                                                   user=kvm_user,
                                                   password=kvm_password)

            if vm_name in kvm_handle.bash('sudo virsh list --all')['content']:
                helpers.summary_log(
                    "VM with given name %s already exists in KVM Host %s" %
                    (vm_name, kvm_host))
                return False

            if qcow_path is not None:
                helpers.log(
                    "QCOW path is provided using it locally NO SCP just copy to images.."
                )
                qcow_vm_path = self._cp_qcow_to_images_folder(
                    kvm_handle=kvm_handle,
                    qcow_path=qcow_path,
                    vm_name=vm_name)
            else:
                helpers.log(
                    "no VMDK path is given copying from latest bvs build from jenkins server"
                )
                if vm_type == 'mininet':
                    helpers.log(
                        "Scp'ing Latest Mininet qcow file from jenkins to kvm Host.."
                    )
                    qcow_vm_path = self._scp_file_to_kvm_host(
                        kvm_handle=kvm_handle,
                        remote_qcow_path=remote_qcow_mininet_path,
                        vm_type='mininet',
                        vm_name=vm_name,
                        build_number=build_number)
                else:
                    helpers.log(
                        "Scp'ing Latest BVS qcow file %s from jenkins to kvm Host.."
                        % remote_qcow_bvs_path)
                    qcow_vm_path = self._scp_file_to_kvm_host(
                        kvm_handle=kvm_handle,
                        remote_qcow_path=remote_qcow_bvs_path,
                        vm_name=vm_name,
                        build_number=build_number)

            helpers.log("Creating VM on KVM Host with Name : %s " % vm_name)
            self.create_vm_on_kvm_host(vm_type=vm_type,
                                       qcow_path=qcow_vm_path,
                                       vm_name=vm_name,
                                       kvm_handle=kvm_handle,
                                       kvm_host=kvm_host,
                                       network_interface=network_interface,
                                       vm_ram=vm_ram)
            result['vm_name'] = vm_name
            result['kvm_host'] = kvm_host
            result['image_path'] = qcow_vm_path
            result['vm_ip'] = ip
            #             result['content'] = helpers.file_read_once("%s/%s.log"
            #                                                        % (self.log_path,
            #                                                           vm_name))

            if vm_type == 'mininet':
                # FIX ME configure mininet with user specified ip / return the DHCP ip of mininet VM
                helpers.log("Success Creating Mininet vm!!")
                helpers.log("Configuring IP for mininet if provided")
                result['vm_ip'] = self.set_mininet_ip(node="c1",
                                                      ip=ip,
                                                      get_ip=True)
                return result

            # For controller, attempt First Boot
            helpers.log("SLeep another 60 sec for controller to boot up..")
            time.sleep(30)
            result['vm_ip'] = self._configure_vm_first_boot(
                cluster_ip=cluster_ip,
                ip_address=ip,
                netmask=netmask,
                vm_host_name=vm_host_name,
                gateway=gateway)
            helpers.summary_log(
                "Copying firstboot-config on New Controller: %s" %
                result['vm_ip'])
            helpers.sleep(10)
            bvs = ControllerDevConf(host=result['vm_ip'],
                                    user="******",
                                    password="******",
                                    name="test-bvs")
            bvs.config("copy running-config snapshot://firstboot-config")
            helpers.summary_log("Success saving firstboot-config")

            helpers.summary_log("Done! Logs are written to %s" % self.log_path)
            return result
        except:
            inst = helpers.exception_info_traceback()
            helpers.log("Exception Details:\n%s" % inst)
            result['status_code'] = False
            result['status_descr'] = inst
            return result