Example #1
0
 def __initLogging(self):
     '''
     @Name : __initLogging
     @Desc : 1. Initializes the logging for marvin and so provides
                 various log features for automation run.
                 2. Initializes all logs to be available under
                 given Folder Path,where all test run logs
                 are available for a given run.
                 3. All logging like exception log,results, run info etc
                  for a given test run are available under a given
                  timestamped folder
     @Output : SUCCESS or FAILED
     '''
     try:
         log_obj = MarvinLog("CSLog")
         if log_obj:
             ret = log_obj.\
                 createLogs(self.__testModName,
                            self.__parsedConfig.logger,
                            self.__userLogFolderPath)
             if ret != FAILED:
                 self.__logFolderPath = log_obj.getLogFolderPath()
                 self.__tcRunLogger = log_obj.getLogger()
                 print "\n=== Marvin Init Logging Successful==="
                 return SUCCESS
         return FAILED
     except Exception as e:
         print "\n Exception Occurred Under __initLogging " \
               ":%s" % GetDetailExceptionInfo(e)
         return FAILED
Example #2
0
 def __initLogging(self):
     '''
     @Name : __initLogging
     @Desc : 1. Initializes the logging for marvin and so provides
                 various log features for automation run.
                 2. Initializes all logs to be available under
                 given Folder Path,where all test run logs
                 are available for a given run.
                 3. All logging like exception log,results, run info etc
                  for a given test run are available under a given
                  timestamped folder
     @Output : SUCCESS or FAILED
     '''
     try:
         log_obj = MarvinLog("CSLog")
         if log_obj:
             ret = log_obj.\
                 createLogs(self.__testModName,
                            self.__parsedConfig.logger,
                            self.__userLogFolderPath)
             if ret != FAILED:
                 self.__logFolderPath = log_obj.getLogFolderPath()
                 self.__tcRunLogger = log_obj.getLogger()
                 print "\n=== Marvin Init Logging Successful==="
                 return SUCCESS
         return FAILED
     except Exception as e:
         print "\n Exception Occurred Under __initLogging " \
               ":%s" % GetDetailExceptionInfo(e)
         return FAILED
Example #3
0
 def __init__(self):
     self.__identifier = None
     self.__testClient = None
     self.__logFolderPath = None
     self.__parsedConfig = None
     '''
     Contains Config File
     '''
     self.__configFile = None
     '''
     Signifies the Zone against which all tests will be Run
     '''
     self.__zoneForTests = None
     '''
     Signifies the flag whether to deploy the New DC or Not
     '''
     self.__deployDcFlag = None
     self.conf = None
     self.__resultStream = stdout
     self.__testRunner = None
     self.__testResult = SUCCESS
     self.__startTime = None
     self.__testName = None
     self.__tcRunLogger = MarvinLog('marvin').getLogger()
     self.__testModName = ''
     self.__hypervisorType = None
     Plugin.__init__(self)
    def setUp(self):
        self.logger = MarvinLog('test').getLogger()
        self.apiclient = self.testClient.getApiClient()
        self.hypervisor = self.testClient.getHypervisorInfo()
        self.cleanup = []
        self.services = self.testClient.getParsedTestDataConfig()
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())

        self.services["sleep"] = 2
        self.services["timeout"] = 240
        # Default value is 120 seconds. That's just too much.
        self.services["configurableData"]["systemVmDelay"] = 60

        return
Example #5
0
    def __initLogging(self):
        try:
            '''
            @Desc : 1. Initializes the logging for marvin and so provides
                    various log features for automation run.
                    2. Initializes all logs to be available under
                    given Folder Path,where all test run logs
                    are available for a given run.
                    3. All logging like exception log,results, run info etc
                     for a given test run are available under a given
                     timestamped folder
            '''
            temp_path = "".join(str(time.time()).split("."))
            if self.__logFolderPath is None:
                log_config = self.__parsedConfig.logger
                if log_config is not None:
                    if log_config.LogFolderPath is not None:
                        self.logFolderPath = log_config.LogFolderPath + '/' \
                            + temp_path
                    else:
                        self.logFolderPath = temp_path
                else:
                    self.logFolderPath = temp_path
            else:
                self.logFolderPath = self.__logFolderPath + '/' + temp_path
            if os.path.exists(self.logFolderPath):
                self.logFolderPath += ''.join(
                    random.choice(string.ascii_uppercase + string.digits
                                  for x in range(3)))
            os.makedirs(self.logFolderPath)
            '''
            Log File Paths
            '''
            tc_failed_exceptionlog = self.logFolderPath + "/failed_" \
                                                          "plus_" \
                                                          "exceptions.txt"
            tc_run_log = self.logFolderPath + "/runinfo.txt"
            self.__tcRunDebugFile = open(self.logFolderPath + "/results.txt",
                                         "w")

            log_obj = MarvinLog("CSLog")
            self.__tcRunLogger = log_obj.setLogHandler(tc_run_log)
            log_obj.setLogHandler(tc_failed_exceptionlog,
                                  log_level=logging.FATAL)
            return SUCCESS
        except Exception, e:
            print "\n Exception Occurred Under __initLogging :%s" % str(e)
            return None
Example #6
0
    def __initLogging(self):
        try:
            '''
            @Desc : 1. Initializes the logging for marvin and so provides
                    various log features for automation run.
                    2. Initializes all logs to be available under
                    given Folder Path,where all test run logs
                    are available for a given run.
                    3. All logging like exception log,results, run info etc
                     for a given test run are available under a given
                     timestamped folder
            '''
            temp_path = "".join(str(time.time()).split("."))
            if self.__logFolderPath is None:
                log_config = self.__parsedConfig.logger
                if log_config is not None:
                    if log_config.LogFolderPath is not None:
                        self.logFolderPath = log_config.LogFolderPath + '/' \
                            + temp_path
                    else:
                        self.logFolderPath = temp_path
                else:
                    self.logFolderPath = temp_path
            else:
                self.logFolderPath = self.__logFolderPath + '/' + temp_path
            if os.path.exists(self.logFolderPath):
                self.logFolderPath += ''.join(random.choice(
                    string.ascii_uppercase +
                    string.digits for x in range(3)))
            os.makedirs(self.logFolderPath)
            '''
            Log File Paths
            '''
            tc_failed_exceptionlog = self.logFolderPath + "/failed_" \
                                                          "plus_" \
                                                          "exceptions.txt"
            tc_run_log = self.logFolderPath + "/runinfo.txt"
            self.__tcRunDebugFile = open(self.logFolderPath +
                                         "/results.txt", "w")

            log_obj = MarvinLog("CSLog")
            self.__tcRunLogger = log_obj.setLogHandler(tc_run_log)
            log_obj.setLogHandler(tc_failed_exceptionlog,
                                  log_level=logging.FATAL)
            return SUCCESS
        except Exception, e:
            print "\n Exception Occurred Under __initLogging :%s" % str(e)
            return None
Example #7
0
    def setUpClass(cls):
        cls.logger = MarvinLog('test').getLogger()

        test_client = super(TestVpcVpn, cls).getClsTestClient()
        cls.apiclient = test_client.getApiClient()
        cls.services = Services().services

        cls.zone = get_zone(cls.apiclient, test_client.getZoneForTests())
        cls.domain = get_domain(cls.apiclient)

        cls.compute_offering = ServiceOffering.create(
            cls.apiclient, cls.services["compute_offering"])

        cls.account = Account.create(cls.apiclient,
                                     services=cls.services["account"])
        cls.logger.debug("Successfully created account: %s, id: %s" %
                         (cls.account.name, cls.account.id))

        cls.hypervisor = test_client.getHypervisorInfo()

        cls._cleanup = [cls.account, cls.compute_offering]

        cls.template = get_template(cls.apiclient, cls.zone.id)

        cls.logger.debug("Retrieving default Network offering for VPCs")
        cls.network_offerings = NetworkOffering.list(
            cls.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        if cls.network_offerings is None or len(cls.network_offerings) <= 0:
            raise Exception("No VPC based network offering")

        return
 def __init__(self):
     self.__identifier = None
     self.__testClient = None
     self.__logFolderPath = None
     self.__parsedConfig = None
     '''
     Contains Config File
     '''
     self.__configFile = None
     '''
     Signifies the Zone against which all tests will be Run
     '''
     self.__zoneForTests = None
     '''
     Signifies the flag whether to deploy the New DC or Not
     '''
     self.__deployDcFlag = None
     self.conf = None
     self.__resultStream = stdout
     self.__testRunner = None
     self.__testResult = SUCCESS
     self.__startTime = None
     self.__testName = None
     self.__tcRunLogger = MarvinLog('marvin').getLogger()
     self.__testModName = ''
     self.__hypervisorType = None
     Plugin.__init__(self)
Example #9
0
 def __init__(self,
              config_file,
              deploy_dc_flag=False,
              test_mod_name="deploydc",
              zone=None,
              hypervisor_type=None):
     self.__configFile = config_file
     self.__deployFlag = deploy_dc_flag
     self.__tcRunLogger = MarvinLog('marvin').getLogger()
     self.__tcRunLogger.info("=== Marvin Init Logging Successful ===")
     self.__testModName = test_mod_name
     self.__testClient = None
     self.__tcResultFile = None
     self.__testDataFilePath = None
     self.__zoneForTests = zone
     self.__parsedConfig = None
     self.__hypervisorType = hypervisor_type
Example #10
0
 def __init__(self, config_file, deploy_dc_flag=False, test_mod_name="deploydc", zone=None, hypervisor_type=None):
     self.__configFile = config_file
     self.__deployFlag = deploy_dc_flag
     self.__tcRunLogger = MarvinLog('marvin').getLogger()
     self.__tcRunLogger.info("=== Marvin Init Logging Successful ===")
     self.__testModName = test_mod_name
     self.__testClient = None
     self.__tcResultFile = None
     self.__testDataFilePath = None
     self.__zoneForTests = zone
     self.__parsedConfig = None
     self.__hypervisorType = hypervisor_type
Example #11
0
class MarvinInit:
    def __init__(self,
                 config_file,
                 deploy_dc_flag=False,
                 test_mod_name="deploydc",
                 zone=None,
                 hypervisor_type=None):
        self.__configFile = config_file
        self.__deployFlag = deploy_dc_flag
        self.__tcRunLogger = MarvinLog('marvin').getLogger()
        self.__tcRunLogger.info("=== Marvin Init Logging Successful ===")
        self.__testModName = test_mod_name
        self.__testClient = None
        self.__tcResultFile = None
        self.__testDataFilePath = None
        self.__zoneForTests = zone
        self.__parsedConfig = None
        self.__hypervisorType = hypervisor_type

    def __parseConfig(self):
        '''
        @Name: __parseConfig
        @Desc : Parses the configuration file passed and assigns
        the parsed configuration
        @Output : SUCCESS or FAILED
        '''
        try:
            if not os.path.isfile(self.__configFile):
                self.__tcRunLogger.error(
                    "=== Marvin Parse Config Init Failed ===")
                return FAILED
            self.__parsedConfig = getSetupConfig(self.__configFile)
            self.__tcRunLogger.info("=== Marvin Parse Config Successful ===")
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Marvin Parse Config Init Failed: %s ===" % e)
            return FAILED

    def getParsedConfig(self):
        return self.__parsedConfig

    def getLogFolderPath(self):
        return self.__logFolderPath

    def getTestClient(self):
        return self.__testClient

    def getLogger(self):
        return self.__tcRunLogger

    def getResultFile(self):
        '''
        @Name : getDebugFile
        @Desc : Creates the result file at a given path.
        @Output : Returns the Result file to be used for writing
                test outputs
        '''
        self.__tcResultFile = open("results.txt", "w")
        return self.__tcResultFile

    def __setHypervisorAndZoneInfo(self):
        '''
        @Name : __setHypervisorAndZoneInfo
        @Desc:  Set the HyperVisor and Zone details;
                default to XenServer
        '''
        try:
            if not self.__hypervisorType:
                if self.__parsedConfig and self.__parsedConfig.zones is not None:
                    for zone in self.__parsedConfig.zones:
                        for pod in zone.pods:
                            if pod is not None:
                                for cluster in pod.clusters:
                                    if cluster is not None and cluster.hypervisor is not None:
                                        self.__hypervisorType = cluster.hypervisor
                                        break
            if not self.__zoneForTests:
                if self.__parsedConfig and self.__parsedConfig.zones is not None:
                    for zone in self.__parsedConfig.zones:
                        self.__zoneForTests = zone.name
                        break
            if not self.__hypervisorType:
                self.__hypervisorType = XEN_SERVER
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Set Hypervizor and Zone info Failed: %s ===" % e)
            return FAILED

    def init(self):
        '''
        @Name : init
        @Desc :Initializes the marvin by
               1. Parsing the configuration and creating a parsed config
                  structure
               2. Creates a timestamped log folder and provides all logs
                  to be dumped there
               3. Creates the DataCenter based upon configuration provided
        @Output : SUCCESS or FAILED
        '''
        try:
            self.__tcRunLogger.info("=== Marvin Init Started ===")
            if ((self.__parseConfig() != FAILED)
                    and (self.__setHypervisorAndZoneInfo())
                    and (self.__setTestDataPath() != FAILED)
                    and (self.__createTestClient() != FAILED)
                    and (self.__deployDC() != FAILED)):
                self.__tcRunLogger.info("=== Marvin Init Successful ===")
                return SUCCESS
            self.__tcRunLogger.error("=== Marvin Init Failed ===")
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Marvin Init Failed with exception: %s ===" % e)
            return FAILED

    def __createTestClient(self):
        '''
        @Name : __createTestClient
        @Desc : Creates the TestClient during init
                based upon the parameters provided
        @Output: Returns SUCCESS or FAILED
        '''
        try:
            mgt_details = self.__parsedConfig.mgtSvr[0]
            dbsvr_details = self.__parsedConfig.dbSvr
            self.__testClient = CSTestClient(
                mgt_details,
                dbsvr_details,
                test_data_filepath=self.__testDataFilePath,
                zone=self.__zoneForTests,
                hypervisor_type=self.__hypervisorType)
            if self.__testClient:
                return self.__testClient.createTestClient()
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Marvin Create Test Client Failed: %s ===" % e)
            return FAILED

    def __setTestDataPath(self):
        '''
        @Name : __setTestDataPath
        @Desc : Sets the TestData Path for tests to run
        @Output:Returns SUCCESS or FAILED
        '''
        try:
            if ((self.__parsedConfig.TestData is not None)
                    and (self.__parsedConfig.TestData.Path is not None)):
                self.__testDataFilePath = self.__parsedConfig.TestData.Path
            self.__tcRunLogger.info(
                "=== Marvin Setting TestData Successful ===")
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Marvin Setting TestData Successful Failed: %s ===" % e)
            return FAILED

    def __deployDC(self):
        '''
        @Name : __deployDC
        @Desc : Deploy the DataCenter and returns accordingly.
        @Output: SUCCESS or FAILED
        '''
        try:
            ret = SUCCESS
            if self.__deployFlag:
                deploy_obj = DeployDataCenters(self.__testClient,
                                               self.__parsedConfig,
                                               self.__tcRunLogger)
                ret = deploy_obj.deploy()
                if ret != SUCCESS:
                    self.__tcRunLogger.error("=== Deploy DC Failed ===")
            return ret
        except Exception as e:
            self.__tcRunLogger.exception(
                "=== Deploy DC Failed with exception: %s ===" % e)
            return FAILED
Example #12
0
        exit(1)

    """
    Imports the Modules Required
    """
    from marvin.marvinLog import MarvinLog
    from marvin.cloudstackTestClient import CSTestClient

    """
    Step1: Create the Logger
    """
    if (options.input) and not (os.path.isfile(options.input)):
        print "\n=== Invalid Input Config File Path, Please Check ==="
        exit(1)

    log_obj = MarvinLog("CSLog")
    cfg = configGenerator.getSetupConfig(options.input)
    log = cfg.logger

    ret = log_obj.createLogs("DeployDataCenter", log)
    if ret != FAILED:
        log_folder_path = log_obj.getLogFolderPath()
        tc_run_logger = log_obj.getLogger()
    else:
        print "\n===Log Creation Failed. Please Check==="
        exit(1)

    """
    Step2 : Create Test Client
    """
    obj_tc_client = CSTestClient(cfg.mgtSvr[0], cfg.dbSvr, logger=tc_run_logger)
Example #13
0
                    where the json config file generated")
  (options, args) = parser.parse_args()

  if options.input is None:
    print "\n==== For cleaning: Please Specify a " \
          "Valid Input Configuration File ===="
    exit(1)

  if (options.input) and not (os.path.isfile(options.input)):
    print "\n=== Invalid Input Config File Path, Please Check ==="
    exit(1)

  from marvin.marvinLog import MarvinLog
  from marvin.cloudstackTestClient import CSTestClient

  log_obj = MarvinLog("CSLogClean")
  cfg = configGenerator.getSetupConfig(options.input)
  log = cfg.logger
  ret = log_obj.createLogs("Clean_Infra", log)
  if ret != FAILED:
    log_folder_path = log_obj.getLogFolderPath()
    tc_run_logger = log_obj.getLogger()
  else:
    print "\n=== Log Creation Failed. Please Check ==="
    exit(1)

  obj_tc_client = CSTestClient(cfg.mgtSvr[0], cfg.dbSvr,
                               logger=tc_run_logger)
  if obj_tc_client and obj_tc_client.createTestClient() == FAILED:
    print "\n=== TestClient Creation Failed ==="
    exit(1)
class TestSSVMs(cloudstackTestCase):
    def setUp(self):
        self.logger = MarvinLog('test').getLogger()
        self.apiclient = self.testClient.getApiClient()
        self.hypervisor = self.testClient.getHypervisorInfo()
        self.cleanup = []
        self.services = self.testClient.getParsedTestDataConfig()
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())

        self.services["sleep"] = 2
        self.services["timeout"] = 240
        # Default value is 120 seconds. That's just too much.
        self.services["configurableData"]["systemVmDelay"] = 60

        return

    def tearDown(self):
        try:
            # Clean up, terminate the created templates
            cleanup_resources(self.apiclient, self.cleanup)

        except Exception as e:
            raise Exception("Warning: Exception during cleanup : %s" % e)
        return

    def wait_for_system_vm_agent(self, vmname):
        self.logger.debug("Waiting for system VM %s agent to be UP" % vmname)
        timeout = self.services["timeout"]
        sleep_interval = self.services["sleep"]
        while timeout > 0:
            list_host_response = list_hosts(self.apiclient, name=vmname)

            if list_host_response and list_host_response[0].state == 'Up':
                self.debug("System VM %s agent is UP" % vmname)
                break

            time.sleep(sleep_interval)
            timeout = timeout - sleep_interval

        if timeout <= 0 and list_host_response[0].state != 'Up':
            self.fail("Timed out waiting for SVM agent to be Up")

    def test_list_svm_vm(self, svm_type):
        # Validate the following:
        # 1. listSystemVM
        #    should return only ONE SVM per zone
        # 2. The returned SVM should be in Running state
        # 3. listSystemVM for should list publicip, privateip and link-localip
        # 4. The gateway programmed on the SVM by listSystemVm should be
        #    the same as the gateway returned by listVlanIpRanges
        # 5. DNS entries must match those given for the zone

        list_svm_response = list_ssvms(
            self.apiclient,
            systemvmtype=svm_type,
            state='Running',
        )
        self.assertEqual(isinstance(list_svm_response, list), True,
                         "Check list response returns a valid list")
        # Verify SSVM response
        self.assertNotEqual(len(list_svm_response), 0,
                            "Check list System VMs response")

        list_zones_response = list_zones(self.apiclient)

        self.assertEqual(isinstance(list_zones_response, list), True,
                         "Check list response returns a valid list")

        self.logger.debug("Number of zones: %s" % len(list_zones_response))
        self.logger.debug("Number of System VMs: %s" % len(list_svm_response))
        # Number of Sec storage VMs = No of Zones
        self.assertEqual(len(list_svm_response), len(list_zones_response),
                         "Check number of System VMs with number of zones")
        # For each secondary storage VM check private IP,
        # public IP, link local IP and DNS
        for svm in list_svm_response:

            self.logger.debug("SVM state: %s" % svm.state)
            self.assertEqual(svm.state, 'Running',
                             "Check whether state of System VM is running")

            self.assertEqual(hasattr(svm, 'privateip'), True,
                             "Check whether System VM has private IP field")

            self.assertEqual(
                hasattr(svm, 'linklocalip'), True,
                "Check whether System VM has link local IP field")

            self.assertEqual(hasattr(svm, 'publicip'), True,
                             "Check whether System VM has public IP field")

            # Fetch corresponding ip ranges information from listVlanIpRanges
            ipranges_response = list_vlan_ipranges(self.apiclient,
                                                   zoneid=svm.zoneid)
            self.assertEqual(isinstance(ipranges_response, list), True,
                             "Check list response returns a valid list")
            iprange = ipranges_response[0]

            # Execute the following assertion in all zones except basic Zones
            if not (self.zone.networktype.lower() == 'basic'):
                self.assertEqual(
                    svm.gateway, iprange.gateway,
                    "Check gateway with that of corresponding ip range")

            # Fetch corresponding zone information from listZones
            zone_response = list_zones(self.apiclient, id=svm.zoneid)
            self.assertEqual(isinstance(zone_response, list), True,
                             "Check list response returns a valid list")
            self.assertEqual(svm.dns1, zone_response[0].dns1,
                             "Check DNS1 with that of corresponding zone")

            self.assertEqual(svm.dns2, zone_response[0].dns2,
                             "Check DNS2 with that of corresponding zone")
        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_01_list_sec_storage_vm(self):
        self.test_list_svm_vm('secondarystoragevm')

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_02_list_cpvm_vm(self):
        self.test_list_svm_vm('consoleproxy')

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_03_ssvm_internals(self):
        """Test SSVM Internals"""

        # Validate the following
        # 1. The SSVM check script should not return any
        #    WARN|ERROR|FAIL messages
        # 2. If you are unable to login to the SSVM with the signed key
        #    then test is deemed a failure
        # 3. There should be only one ""cloud"" process running within the SSVM
        # 4. If no process is running/multiple process are running
        #    then the test is a failure

        list_ssvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='secondarystoragevm',
                                        state='Running',
                                        zoneid=self.zone.id)
        self.assertEqual(isinstance(list_ssvm_response, list), True,
                         "Check list response returns a valid list")
        ssvm = list_ssvm_response[0]

        hosts = list_hosts(self.apiclient, id=ssvm.hostid)
        self.assertEqual(isinstance(hosts, list), True,
                         "Check list response returns a valid list")
        host = hosts[0]

        self.logger.debug("Running SSVM check script")

        try:
            host.user, host.passwd = get_host_credentials(
                self.config, host.ipaddress)
            result = get_process_status(
                host.ipaddress, 22, host.user, host.passwd, ssvm.linklocalip,
                "/opt/cosmic/agent/ssvm-check.sh |grep -e ERROR -e WARNING -e FAIL"
            )
        except KeyError:
            self.skipTest(
                "Marvin configuration has no host credentials to check router services"
            )

        res = str(result)
        self.logger.debug("SSVM script output: %s" % res)

        self.assertEqual(res.count("ERROR"), 1, "Check for Errors in tests")

        self.assertEqual(res.count("WARNING"), 1,
                         "Check for warnings in tests")

        # Check status of cloud service
        try:
            host.user, host.passwd = get_host_credentials(
                self.config, host.ipaddress)
            result = get_process_status(host.ipaddress, 22, host.user,
                                        host.passwd, ssvm.linklocalip,
                                        "service cloud status")
        except KeyError:
            self.skipTest(
                "Marvin configuration has no host credentials to check router services"
            )
        res = str(result)
        self.logger.debug("Cloud Process status: %s" % res)
        # cloud.com service (type=secstorage) is running: process id: 2346
        self.assertEqual(res.count("is running"), 1,
                         "Check cloud service is running or not")

        linklocal_ip = None
        # Check status of cloud service
        try:
            linklocal_ip = ssvm.linklocalip
            host.user, host.passwd = get_host_credentials(
                self.config, host.ipaddress)
            result = get_process_status(
                host.ipaddress, 22, host.user, host.passwd, ssvm.linklocalip,
                "cat /var/cache/cloud/cmdline | xargs | sed \"s/ /\\n/g\" | grep eth0ip= | sed \"s/\=/ /g\" | awk '{print $2}'"
            )
        except KeyError:
            self.skipTest(
                "Marvin configuration has no host credentials to check router services"
            )
        res = result[0]
        self.logger.debug("Cached Link Local IP: %s" % res)
        self.assertEqual(
            linklocal_ip, res,
            "The cached Link Local should be the same as the current Link Local IP, but they are different! Current ==> %s; Cached ==> %s "
            % (linklocal_ip, res))

        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_04_cpvm_internals(self):
        """Test CPVM Internals"""

        # Validate the following
        # 1. test that telnet access on 8250 is available to
        #    the management server for the CPVM
        # 2. No telnet access, test FAIL
        # 3. Service cloud status should report cloud agent status to be
        #    running

        list_cpvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='consoleproxy',
                                        state='Running',
                                        zoneid=self.zone.id)
        self.assertEqual(isinstance(list_cpvm_response, list), True,
                         "Check list response returns a valid list")
        cpvm = list_cpvm_response[0]

        hosts = list_hosts(self.apiclient, id=cpvm.hostid)
        self.assertEqual(isinstance(hosts, list), True,
                         "Check list response returns a valid list")
        host = hosts[0]

        try:
            telnetlib.Telnet(str(self.apiclient.connection.mgtSvr), '8250')
            self.logger.debug("Telnet management server (IP: %s)" %
                              self.apiclient.connection.mgtSvr)
        except Exception as e:
            self.fail("Telnet Access failed for %s: %s" %
                      (self.apiclient.connection.mgtSvr, e))

        self.logger.debug("Checking cloud process status")

        try:
            host.user, host.passwd = get_host_credentials(
                self.config, host.ipaddress)
            result = get_process_status(host.ipaddress, 22, host.user,
                                        host.passwd, cpvm.linklocalip,
                                        "service cloud status")
        except KeyError:
            self.skipTest(
                "Marvin configuration has no host credentials to check router services"
            )
        res = str(result)
        self.logger.debug("Cloud Process status: %s" % res)
        self.assertEqual(res.count("is running"), 1,
                         "Check cloud service is running or not")

        linklocal_ip = None
        # Check status of cloud service
        try:
            linklocal_ip = cpvm.linklocalip
            host.user, host.passwd = get_host_credentials(
                self.config, host.ipaddress)
            result = get_process_status(
                host.ipaddress, 22, host.user, host.passwd, cpvm.linklocalip,
                "cat /var/cache/cloud/cmdline | xargs | sed \"s/ /\\n/g\" | grep eth0ip= | sed \"s/\=/ /g\" | awk '{print $2}'"
            )
        except KeyError:
            self.skipTest(
                "Marvin configuration has no host credentials to check router services"
            )
        res = result[0]
        self.logger.debug("Cached Link Local IP: %s" % res)
        self.assertEqual(
            linklocal_ip, res,
            "The cached Link Local should be the same as the current Link Local IP, but they are different! Current ==> %s; Cached ==> %s "
            % (linklocal_ip, res))

        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_07_reboot_ssvm(self):
        """Test reboot SSVM
        """
        # Validate the following
        # 1. The SSVM should go to stop and return to Running state
        # 2. SSVM's public-ip and private-ip must remain the same
        #    before and after reboot
        # 3. The cloud process should still be running within the SSVM

        list_ssvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='secondarystoragevm',
                                        state='Running',
                                        zoneid=self.zone.id)

        self.assertEqual(isinstance(list_ssvm_response, list), True,
                         "Check list response returns a valid list")

        ssvm_response = list_ssvm_response[0]

        hosts = list_hosts(self.apiclient, id=ssvm_response.hostid)
        self.assertEqual(isinstance(hosts, list), True,
                         "Check list response returns a valid list")

        # Store the public & private IP values before reboot
        old_public_ip = ssvm_response.publicip
        old_private_ip = ssvm_response.privateip

        self.logger.debug("Rebooting SSVM: %s" % ssvm_response.id)
        cmd = rebootSystemVm.rebootSystemVmCmd()
        cmd.id = ssvm_response.id
        self.apiclient.rebootSystemVm(cmd)

        timeout = self.services["timeout"]
        while True:
            list_ssvm_response = list_ssvms(self.apiclient,
                                            id=ssvm_response.id)
            if isinstance(list_ssvm_response, list):
                if list_ssvm_response[0].state == 'Running':
                    break
            if timeout == 0:
                raise Exception("List SSVM call failed!")

            time.sleep(self.services["sleep"])
            timeout = timeout - 1

        ssvm_response = list_ssvm_response[0]
        self.logger.debug("SSVM State: %s" % ssvm_response.state)
        self.assertEqual('Running', str(ssvm_response.state),
                         "Check whether CPVM is running or not")

        self.assertEqual(
            ssvm_response.publicip, old_public_ip,
            "Check Public IP after reboot with that of before reboot")

        # Private IP Address of System VMs are allowed to change after reboot - CLOUDSTACK-7745

        # Wait for the agent to be up
        self.wait_for_system_vm_agent(ssvm_response.name)

        # Wait for some time before running diagnostic scripts on SSVM
        # as it may take some time to start all service properly
        time.sleep(int(self.services["configurableData"]["systemVmDelay"]))

        # Call to verify cloud process is running
        self.test_03_ssvm_internals()
        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_08_reboot_cpvm(self):
        """Test reboot CPVM
        """
        # Validate the following
        # 1. The CPVM should go to stop and return to Running state
        # 2. CPVM's public-ip and private-ip must remain
        #    the same before and after reboot
        # 3. the cloud process should still be running within the CPVM

        list_cpvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='consoleproxy',
                                        state='Running',
                                        zoneid=self.zone.id)
        self.assertEqual(isinstance(list_cpvm_response, list), True,
                         "Check list response returns a valid list")
        cpvm_response = list_cpvm_response[0]

        hosts = list_hosts(self.apiclient, id=cpvm_response.hostid)
        self.assertEqual(isinstance(hosts, list), True,
                         "Check list response returns a valid list")

        # Store the public & private IP values before reboot
        old_public_ip = cpvm_response.publicip
        old_private_ip = cpvm_response.privateip

        self.logger.debug("Rebooting CPVM: %s" % cpvm_response.id)

        cmd = rebootSystemVm.rebootSystemVmCmd()
        cmd.id = cpvm_response.id
        self.apiclient.rebootSystemVm(cmd)

        timeout = self.services["timeout"]
        while True:
            list_cpvm_response = list_ssvms(self.apiclient,
                                            id=cpvm_response.id)
            if isinstance(list_cpvm_response, list):
                if list_cpvm_response[0].state == 'Running':
                    break
            if timeout == 0:
                raise Exception("List CPVM call failed!")

            time.sleep(self.services["sleep"])
            timeout = timeout - 1

        cpvm_response = list_cpvm_response[0]

        self.logger.debug("CPVM state: %s" % cpvm_response.state)
        self.assertEqual('Running', str(cpvm_response.state),
                         "Check whether CPVM is running or not")

        self.assertEqual(
            cpvm_response.publicip, old_public_ip,
            "Check Public IP after reboot with that of before reboot")

        # Private IP Address of System VMs are allowed to change after reboot - CLOUDSTACK-7745

        # Wait for the agent to be up
        self.wait_for_system_vm_agent(cpvm_response.name)

        # Wait for some time before running diagnostic scripts on SSVM
        # as it may take some time to start all service properly
        time.sleep(int(self.services["configurableData"]["systemVmDelay"]))

        # Call to verify cloud process is running
        self.test_04_cpvm_internals()
        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_09_destroy_ssvm(self):
        """Test destroy SSVM
        """

        # Validate the following
        # 1. SSVM should be completely destroyed and a new one will spin up
        # 2. listSystemVMs will show a different name for the
        #    systemVM from what it was before
        # 3. new SSVM will have a public/private and link-local-ip
        # 4. cloud process within SSVM must be up and running

        list_ssvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='secondarystoragevm',
                                        state='Running',
                                        zoneid=self.zone.id)
        self.assertEqual(isinstance(list_ssvm_response, list), True,
                         "Check list response returns a valid list")
        ssvm_response = list_ssvm_response[0]

        old_name = ssvm_response.name

        self.logger.debug("Destroying SSVM: %s" % ssvm_response.id)
        cmd = destroySystemVm.destroySystemVmCmd()
        cmd.id = ssvm_response.id
        self.apiclient.destroySystemVm(cmd)

        timeout = self.services["timeout"]
        while True:
            list_ssvm_response = list_ssvms(self.apiclient,
                                            zoneid=self.zone.id,
                                            systemvmtype='secondarystoragevm')
            if isinstance(list_ssvm_response, list):
                if list_ssvm_response[0].state == 'Running':
                    break
            if timeout == 0:
                self.logger.debug(
                    "Warning: List SSVM didn't return systemvms in Running state. This is a known issue, ignoring it for now!"
                )
                return

            time.sleep(self.services["sleep"])
            timeout = timeout - 1

        ssvm_response = list_ssvm_response[0]

        # Verify Name, Public IP, Private IP and Link local IP
        # for newly created SSVM
        self.assertNotEqual(ssvm_response.name, old_name,
                            "Check SSVM new name with name of destroyed SSVM")
        self.assertEqual(hasattr(ssvm_response, 'privateip'), True,
                         "Check whether SSVM has private IP field")

        self.assertEqual(hasattr(ssvm_response, 'linklocalip'), True,
                         "Check whether SSVM has link local IP field")

        self.assertEqual(hasattr(ssvm_response, 'publicip'), True,
                         "Check whether SSVM has public IP field")

        # Wait for the agent to be up
        self.wait_for_system_vm_agent(ssvm_response.name)

        # Wait for some time before running diagnostic scripts on SSVM
        # as it may take some time to start all service properly
        time.sleep(int(self.services["configurableData"]["systemVmDelay"]))

        # Call to verify cloud process is running
        self.test_03_ssvm_internals()
        return

    @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"],
          required_hardware="true")
    def test_10_destroy_cpvm(self):
        """Test destroy CPVM
        """

        # Validate the following
        # 1. CPVM should be completely destroyed and a new one will spin up
        # 2. listSystemVMs will show a different name for the systemVM from
        #    what it was before
        # 3. new CPVM will have a public/private and link-local-ip
        # 4. cloud process within CPVM must be up and running

        list_cpvm_response = list_ssvms(self.apiclient,
                                        systemvmtype='consoleproxy',
                                        zoneid=self.zone.id)
        self.assertEqual(isinstance(list_cpvm_response, list), True,
                         "Check list response returns a valid list")
        cpvm_response = list_cpvm_response[0]

        old_name = cpvm_response.name

        self.logger.debug("Destroying CPVM: %s" % cpvm_response.id)
        cmd = destroySystemVm.destroySystemVmCmd()
        cmd.id = cpvm_response.id
        self.apiclient.destroySystemVm(cmd)

        timeout = self.services["timeout"]
        while True:
            list_cpvm_response = list_ssvms(self.apiclient,
                                            systemvmtype='consoleproxy',
                                            zoneid=self.zone.id)
            if isinstance(list_cpvm_response, list):
                if list_cpvm_response[0].state == 'Running':
                    break
            if timeout == 0:
                self.logger.debug(
                    "Warning: List CPVM didn't return systemvms in Running state. This is a known issue, ignoring it for now!"
                )
                return

            time.sleep(self.services["sleep"])
            timeout = timeout - 1

        cpvm_response = list_cpvm_response[0]

        # Verify Name, Public IP, Private IP and Link local IP
        # for newly created CPVM
        self.assertNotEqual(cpvm_response.name, old_name,
                            "Check SSVM new name with name of destroyed CPVM")
        self.assertEqual(hasattr(cpvm_response, 'privateip'), True,
                         "Check whether CPVM has private IP field")

        self.assertEqual(hasattr(cpvm_response, 'linklocalip'), True,
                         "Check whether CPVM has link local IP field")

        self.assertEqual(hasattr(cpvm_response, 'publicip'), True,
                         "Check whether CPVM has public IP field")

        # Wait for the agent to be up
        self.wait_for_system_vm_agent(cpvm_response.name)

        # Wait for some time before running diagnostic scripts on SSVM
        # as it may take some time to start all service properly
        time.sleep(int(self.services["configurableData"]["systemVmDelay"]))

        # Call to verify cloud process is running
        self.test_04_cpvm_internals()
        return
Example #15
0
class MarvinInit:
    def __init__(self, config_file, deploy_dc_flag=False, test_mod_name="deploydc", zone=None, hypervisor_type=None):
        self.__configFile = config_file
        self.__deployFlag = deploy_dc_flag
        self.__tcRunLogger = MarvinLog('marvin').getLogger()
        self.__tcRunLogger.info("=== Marvin Init Logging Successful ===")
        self.__testModName = test_mod_name
        self.__testClient = None
        self.__tcResultFile = None
        self.__testDataFilePath = None
        self.__zoneForTests = zone
        self.__parsedConfig = None
        self.__hypervisorType = hypervisor_type

    def __parseConfig(self):
        '''
        @Name: __parseConfig
        @Desc : Parses the configuration file passed and assigns
        the parsed configuration
        @Output : SUCCESS or FAILED
        '''
        try:
            if not os.path.isfile(self.__configFile):
                self.__tcRunLogger.error("=== Marvin Parse Config Init Failed ===")
                return FAILED
            self.__parsedConfig = getSetupConfig(self.__configFile)
            self.__tcRunLogger.info("=== Marvin Parse Config Successful ===")
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception("=== Marvin Parse Config Init Failed: %s ===" % e)
            return FAILED

    def getParsedConfig(self):
        return self.__parsedConfig

    def getLogFolderPath(self):
        return self.__logFolderPath

    def getTestClient(self):
        return self.__testClient

    def getLogger(self):
        return self.__tcRunLogger

    def getResultFile(self):
        '''
        @Name : getDebugFile
        @Desc : Creates the result file at a given path.
        @Output : Returns the Result file to be used for writing
                test outputs
        '''
        self.__tcResultFile = open("results.txt", "w")
        return self.__tcResultFile

    def __setHypervisorAndZoneInfo(self):
        '''
        @Name : __setHypervisorAndZoneInfo
        @Desc:  Set the HyperVisor and Zone details;
                default to XenServer
        '''
        try:
            if not self.__hypervisorType:
                if self.__parsedConfig and self.__parsedConfig.zones is not None:
                    for zone in self.__parsedConfig.zones:
                        for pod in zone.pods:
                            if pod is not None:
                                for cluster in pod.clusters:
                                    if cluster is not None and cluster.hypervisor is not None:
                                        self.__hypervisorType = cluster.hypervisor
                                        break
            if not self.__zoneForTests:
                if self.__parsedConfig and self.__parsedConfig.zones is not None:
                    for zone in self.__parsedConfig.zones:
                        self.__zoneForTests = zone.name
                        break
            if not self.__hypervisorType:
                self.__hypervisorType = XEN_SERVER
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception("=== Set Hypervizor and Zone info Failed: %s ===" % e)
            return FAILED

    def init(self):
        '''
        @Name : init
        @Desc :Initializes the marvin by
               1. Parsing the configuration and creating a parsed config
                  structure
               2. Creates a timestamped log folder and provides all logs
                  to be dumped there
               3. Creates the DataCenter based upon configuration provided
        @Output : SUCCESS or FAILED
        '''
        try:
            self.__tcRunLogger.info("=== Marvin Init Started ===")
            if ((self.__parseConfig() != FAILED) and
                    (self.__setHypervisorAndZoneInfo()) and
                    (self.__setTestDataPath() != FAILED) and
                    (self.__createTestClient() != FAILED) and
                    (self.__deployDC() != FAILED)):
                self.__tcRunLogger.info("=== Marvin Init Successful ===")
                return SUCCESS
            self.__tcRunLogger.error("=== Marvin Init Failed ===")
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception("=== Marvin Init Failed with exception: %s ===" % e)
            return FAILED

    def __createTestClient(self):
        '''
        @Name : __createTestClient
        @Desc : Creates the TestClient during init
                based upon the parameters provided
        @Output: Returns SUCCESS or FAILED
        '''
        try:
            mgt_details = self.__parsedConfig.mgtSvr[0]
            dbsvr_details = self.__parsedConfig.dbSvr
            self.__testClient = CSTestClient(
                mgt_details,
                dbsvr_details,
                test_data_filepath=self.__testDataFilePath,
                zone=self.__zoneForTests,
                hypervisor_type=self.__hypervisorType)
            if self.__testClient:
                return self.__testClient.createTestClient()
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception("=== Marvin Create Test Client Failed: %s ===" % e)
            return FAILED

    def __setTestDataPath(self):
        '''
        @Name : __setTestDataPath
        @Desc : Sets the TestData Path for tests to run
        @Output:Returns SUCCESS or FAILED
        '''
        try:
            if ((self.__parsedConfig.TestData is not None) and
                    (self.__parsedConfig.TestData.Path is not None)):
                self.__testDataFilePath = self.__parsedConfig.TestData.Path
            self.__tcRunLogger.info("=== Marvin Setting TestData Successful ===")
            return SUCCESS
        except Exception as e:
            self.__tcRunLogger.exception("=== Marvin Setting TestData Successful Failed: %s ===" % e)
            return FAILED

    def __deployDC(self):
        '''
        @Name : __deployDC
        @Desc : Deploy the DataCenter and returns accordingly.
        @Output: SUCCESS or FAILED
        '''
        try:
            ret = SUCCESS
            if self.__deployFlag:
                deploy_obj = DeployDataCenters(self.__testClient,
                                               self.__parsedConfig,
                                               self.__tcRunLogger)
                ret = deploy_obj.deploy()
                if ret != SUCCESS:
                    self.__tcRunLogger.error("=== Deploy DC Failed ===")
            return ret
        except Exception as e:
            self.__tcRunLogger.exception("=== Deploy DC Failed with exception: %s ===" % e)
            return FAILED
Example #16
0
    def test_create_marvin_log_with_name(self):
        name = 'test-log'
        marvin_log = MarvinLog(name)

        self.assertIsNotNone(marvin_log)
        self.assertEquals(name, marvin_log.getLogger().name)
Example #17
0
          "Valid Input Configuration File ===="
    exit(1)

  if (options.upload_iso is None) and (options.upload_tmpl is None):
    print "\n==== For uploading file: Please Specify a " \
          "HTTP path for file ===="
    exit(1)

  if (options.input) and not (os.path.isfile(options.input)):
    print "\n=== Invalid Input Config File Path, Please Check ==="
    exit(1)

  from marvin.marvinLog import MarvinLog
  from marvin.cloudstackTestClient import CSTestClient

  log_obj = MarvinLog("CSLogTemplates")
  cfg = configGenerator.getSetupConfig(options.input)
  log = cfg.logger
  ret = log_obj.createLogs("UploadTemplates", log)
  if ret != FAILED:
    log_folder_path = log_obj.getLogFolderPath()
    tc_run_logger = log_obj.getLogger()
  else:
    print "\n=== Log Creation Failed. Please Check ==="
    exit(1)

  obj_tc_client = CSTestClient(cfg.mgtSvr[0], cfg.dbSvr,
                               logger=tc_run_logger)
  if obj_tc_client and obj_tc_client.createTestClient() == FAILED:
    print "\n=== TestClient Creation Failed ==="
    exit(1)
class MarvinPlugin(Plugin):
    """
    Custom plugin for the cloudstackTestCases to be run using nose
    """

    name = "marvin"

    def __init__(self):
        self.__identifier = None
        self.__testClient = None
        self.__logFolderPath = None
        self.__parsedConfig = None
        '''
        Contains Config File
        '''
        self.__configFile = None
        '''
        Signifies the Zone against which all tests will be Run
        '''
        self.__zoneForTests = None
        '''
        Signifies the flag whether to deploy the New DC or Not
        '''
        self.__deployDcFlag = None
        self.conf = None
        self.__resultStream = stdout
        self.__testRunner = None
        self.__testResult = SUCCESS
        self.__startTime = None
        self.__testName = None
        self.__tcRunLogger = MarvinLog('marvin').getLogger()
        self.__testModName = ''
        self.__hypervisorType = None
        Plugin.__init__(self)

    def configure(self, options, conf):
        """enable the marvin plugin when the --with-marvin directive is given
        to nose. The enableOpt value is set from the command line directive and
        self.enabled (True|False) determines whether marvin's tests will run.
        By default non-default plugins like marvin will be disabled
        """
        self.enabled = True
        if hasattr(options, self.enableOpt):
            if not getattr(options, self.enableOpt):
                self.enabled = False
                return
        self.__configFile = options.configFile
        self.__deployDcFlag = options.deployDc
        self.__zoneForTests = options.zone
        self.__hypervisorType = options.hypervisor_type
        self.conf = conf
        if self.startMarvin() == FAILED:
            self.__tcRunLogger.error('Starting Marvin Failed, exiting. Please Check')
            exit(1)

    def options(self, parser, env):
        """
        Register command line options
        """
        parser.add_option("--marvin-config", action="store",
                          default=env.get('MARVIN_CONFIG',
                                          './datacenter.cfg'),
                          dest="configFile",
                          help="Marvin's configuration file is required."
                               "The config file containing the datacenter and "
                               "other management server "
                               "information is specified")
        parser.add_option("--deploy", action="store_true",
                          default=False,
                          dest="deployDc",
                          help="Deploys the DC with Given Configuration."
                               "Requires only when DC needs to be deployed")
        parser.add_option("--zone", action="store",
                          default=None,
                          dest="zone",
                          help="Runs all tests against this specified zone")
        parser.add_option("--hypervisor", action="store",
                          default=None,
                          dest="hypervisor_type",
                          help="Runs all tests against the specified "
                               "zone and hypervisor Type")
        parser.add_option("--log-folder-path", action="store",
                          default=None,
                          dest="logFolder",
                          help="Collects all logs under the user specified"
                               "folder"
                          )
        Plugin.options(self, parser, env)

    def wantClass(self, cls):
        if cls.__name__ == 'cloudstackTestCase':
            return False
        if issubclass(cls, cloudstackTestCase):
            return True
        return None

    def __checkImport(self, filename):
        '''
        @Name : __checkImport
        @Desc : Verifies if a test module is importable.
                Returns False or True based upon the result.
        '''
        try:
            if os.path.isfile(filename):
                ret = os.path.splitext(filename)
                if ret[1] == ".py":
                    os.system("python " + filename)
                    return True
            return False
        except ImportError as e:
            self.__tcRunLogger.exception("File %s has import errors: %s" % (filename, e))
            return False

    def wantFile(self, filename):
        '''
        @Desc : Only python files will be used as test modules
        '''
        return self.__checkImport(filename)

    def loadTestsFromTestCase(self, cls):
        if cls.__name__ != 'cloudstackTestCase':
            self.__identifier = cls.__name__
            self._injectClients(cls)

    def beforeTest(self, test):
        self.__testModName = test.__str__()
        self.__testName = test.__str__().split()[0]
        if not self.__testName:
            self.__testName = "test"
        self.__testClient.identifier = '-'. \
            join([self.__identifier, self.__testName])
        if self.__tcRunLogger:
            self.__tcRunLogger.name = test.__str__()

    def startTest(self, test):
        """
        Currently used to record start time for tests
        Dump Start Msg of TestCase to Log
        """
        self.__tcRunLogger.info("=== Started Test %s ===" % str(self.__testName))
        self.__startTime = time.time()

    def printMsg(self, status, tname, err):
        if status in [FAILED, EXCEPTION] and self.__tcRunLogger:
            self.__tcRunLogger.fatal("%s: %s: %s" % (status, tname, err))
        write_str = "=== TestName: %s | Status : %s ===" % (tname, status)
        self.__resultStream.write(write_str)
        self.__tcRunLogger.info(write_str)

    def addSuccess(self, test, capt):
        '''
        Adds the Success Messages to logs
        '''
        self.printMsg(SUCCESS, self.__testName, "Test Case Passed")
        self.__testResult = SUCCESS

    def handleError(self, test, err):
        '''
        Adds Exception throwing test cases and information to log.
        '''
        self.printMsg(EXCEPTION, self.__testName, err)
        self.__testResult = EXCEPTION

    def prepareTestRunner(self, runner):
        if self.__testRunner:
            return self.__testRunner

    def handleFailure(self, test, err):
        '''
        Adds Failing test cases and information to log.
        '''
        self.printMsg(FAILED, self.__testName, err)
        self.__testResult = FAILED

    def startMarvin(self):
        '''
        @Name : startMarvin
        @Desc : Initializes the Marvin
                creates the test Client
                creates the runlogger for logging
                Parses the config and creates a parsedconfig
                Creates a debugstream for tc debug log
        '''
        try:
            obj_marvininit = MarvinInit(self.__configFile,
                                        self.__deployDcFlag,
                                        None,
                                        self.__zoneForTests,
                                        self.__hypervisorType)
            if obj_marvininit and obj_marvininit.init() == SUCCESS:
                self.__testClient = obj_marvininit.getTestClient()
                self.__parsedConfig = obj_marvininit.getParsedConfig()
                self.__resultStream = obj_marvininit.getResultFile()
                self.__testRunner = nose.core.TextTestRunner(
                    stream=self.__resultStream,
                    descriptions=True,
                    verbosity=2,
                    config=self.conf
                )
                return SUCCESS
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception(("=== Start Marvin failed: %s ===" % e))
            return FAILED

    def stopTest(self, test):
        """
        Currently used to record end time for tests
        """
        endTime = time.time()
        if self.__startTime:
            totTime = int(endTime - self.__startTime)
            self.__tcRunLogger.info(
                "TestCaseName: %s; Time Taken: %s Seconds; StartTime: %s; EndTime: %s; Result: %s" % (
                    self.__testName,
                    str(totTime),
                    str(time.ctime(self.__startTime)),
                    str(time.ctime(endTime)),
                    self.__testResult
                )
            )

    def _injectClients(self, test):
        setattr(test, "debug", self.__tcRunLogger.debug)
        setattr(test, "info", self.__tcRunLogger.info)
        setattr(test, "warn", self.__tcRunLogger.warning)
        setattr(test, "error", self.__tcRunLogger.error)
        setattr(test, "testClient", self.__testClient)
        setattr(test, "config", self.__parsedConfig)
        if self.__testClient.identifier is None:
            self.__testClient.identifier = self.__identifier
        setattr(test, "clstestclient", self.__testClient)
        if hasattr(test, "user"):
            # when the class-level attr applied. all test runs as 'user'
            self.__testClient.getUserApiClient(test.UserName,
                                               test.DomainName,
                                               test.AcctType)

    def finalize(self, result):
        self.__tcRunLogger.info('=== finalize does nothing!  ===')
        self.loadCfg()
        self.updateConfiguration(self.config.globalConfig)
        self.createZones(self.config.zones)
        self.configureS3(self.config.s3)

if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option("-i", "--input", action="store",
                      default="./datacenterCfg", dest="input", help="the path \
                      where the json config file generated, by default is \
                      ./datacenterCfg")

    (options, args) = parser.parse_args()
    from marvin.marvinLog import MarvinLog
    cfg = configGenerator.getSetupConfig(options.input)
    log_obj = MarvinLog("CSLog")
    tcRunLogger = log_obj.setLogHandler("/tmp/debug.log")
    deploy = deployDataCenters(cfg, tcRunLogger)
    deploy.deploy()

    """
    create = createStoragePool.createStoragePoolCmd()
    create.clusterid = 1
    create.podid = 2
    create.name = "fdffdf"
    create.url = "nfs://jfkdjf/fdkjfkd"
    create.zoneid = 2

    deploy = deployDataCenters("./datacenterCfg")
    deploy.loadCfg()
    deploy.apiClient.createStoragePool(create)
Example #20
0
class MarvinPlugin(Plugin):
    """
    Custom plugin for the cloudstackTestCases to be run using nose
    """

    name = "marvin"

    def __init__(self):
        self.__identifier = None
        self.__testClient = None
        self.__logFolderPath = None
        self.__parsedConfig = None
        '''
        Contains Config File
        '''
        self.__configFile = None
        '''
        Signifies the Zone against which all tests will be Run
        '''
        self.__zoneForTests = None
        '''
        Signifies the flag whether to deploy the New DC or Not
        '''
        self.__deployDcFlag = None
        self.conf = None
        self.__resultStream = stdout
        self.__testRunner = None
        self.__testResult = SUCCESS
        self.__startTime = None
        self.__testName = None
        self.__tcRunLogger = MarvinLog('marvin').getLogger()
        self.__testModName = ''
        self.__hypervisorType = None
        Plugin.__init__(self)

    def configure(self, options, conf):
        """enable the marvin plugin when the --with-marvin directive is given
        to nose. The enableOpt value is set from the command line directive and
        self.enabled (True|False) determines whether marvin's tests will run.
        By default non-default plugins like marvin will be disabled
        """
        self.enabled = True
        if hasattr(options, self.enableOpt):
            if not getattr(options, self.enableOpt):
                self.enabled = False
                return
        self.__configFile = options.configFile
        self.__deployDcFlag = options.deployDc
        self.__zoneForTests = options.zone
        self.__hypervisorType = options.hypervisor_type
        self.conf = conf
        if self.startMarvin() == FAILED:
            self.__tcRunLogger.error(
                'Starting Marvin Failed, exiting. Please Check')
            exit(1)

    def options(self, parser, env):
        """
        Register command line options
        """
        parser.add_option("--marvin-config",
                          action="store",
                          default=env.get('MARVIN_CONFIG', './datacenter.cfg'),
                          dest="configFile",
                          help="Marvin's configuration file is required."
                          "The config file containing the datacenter and "
                          "other management server "
                          "information is specified")
        parser.add_option("--deploy",
                          action="store_true",
                          default=False,
                          dest="deployDc",
                          help="Deploys the DC with Given Configuration."
                          "Requires only when DC needs to be deployed")
        parser.add_option("--zone",
                          action="store",
                          default=None,
                          dest="zone",
                          help="Runs all tests against this specified zone")
        parser.add_option("--hypervisor",
                          action="store",
                          default=None,
                          dest="hypervisor_type",
                          help="Runs all tests against the specified "
                          "zone and hypervisor Type")
        parser.add_option("--log-folder-path",
                          action="store",
                          default=None,
                          dest="logFolder",
                          help="Collects all logs under the user specified"
                          "folder")
        Plugin.options(self, parser, env)

    def wantClass(self, cls):
        if cls.__name__ == 'cloudstackTestCase':
            return False
        if issubclass(cls, cloudstackTestCase):
            return True
        return None

    def __checkImport(self, filename):
        '''
        @Name : __checkImport
        @Desc : Verifies if a test module is importable.
                Returns False or True based upon the result.
        '''
        try:
            if os.path.isfile(filename):
                ret = os.path.splitext(filename)
                if ret[1] == ".py":
                    os.system("python " + filename)
                    return True
            return False
        except ImportError as e:
            self.__tcRunLogger.exception("File %s has import errors: %s" %
                                         (filename, e))
            return False

    def wantFile(self, filename):
        '''
        @Desc : Only python files will be used as test modules
        '''
        return self.__checkImport(filename)

    def loadTestsFromTestCase(self, cls):
        if cls.__name__ != 'cloudstackTestCase':
            self.__identifier = cls.__name__
            self._injectClients(cls)

    def beforeTest(self, test):
        self.__testModName = test.__str__()
        self.__testName = test.__str__().split()[0]
        if not self.__testName:
            self.__testName = "test"
        self.__testClient.identifier = '-'. \
            join([self.__identifier, self.__testName])
        if self.__tcRunLogger:
            self.__tcRunLogger.name = test.__str__()

    def startTest(self, test):
        """
        Currently used to record start time for tests
        Dump Start Msg of TestCase to Log
        """
        self.__tcRunLogger.info("=== Started Test %s ===" %
                                str(self.__testName))
        self.__startTime = time.time()

    def printMsg(self, status, tname, err):
        if status in [FAILED, EXCEPTION] and self.__tcRunLogger:
            self.__tcRunLogger.fatal("%s: %s: %s" % (status, tname, err))
        write_str = "=== TestName: %s | Status : %s ===" % (tname, status)
        self.__resultStream.write(write_str)
        self.__tcRunLogger.info(write_str)

    def addSuccess(self, test, capt):
        '''
        Adds the Success Messages to logs
        '''
        self.printMsg(SUCCESS, self.__testName, "Test Case Passed")
        self.__testResult = SUCCESS

    def handleError(self, test, err):
        '''
        Adds Exception throwing test cases and information to log.
        '''
        self.printMsg(EXCEPTION, self.__testName, err)
        self.__testResult = EXCEPTION

    def prepareTestRunner(self, runner):
        if self.__testRunner:
            return self.__testRunner

    def handleFailure(self, test, err):
        '''
        Adds Failing test cases and information to log.
        '''
        self.printMsg(FAILED, self.__testName, err)
        self.__testResult = FAILED

    def startMarvin(self):
        '''
        @Name : startMarvin
        @Desc : Initializes the Marvin
                creates the test Client
                creates the runlogger for logging
                Parses the config and creates a parsedconfig
                Creates a debugstream for tc debug log
        '''
        try:
            obj_marvininit = MarvinInit(self.__configFile, self.__deployDcFlag,
                                        None, self.__zoneForTests,
                                        self.__hypervisorType)
            if obj_marvininit and obj_marvininit.init() == SUCCESS:
                self.__testClient = obj_marvininit.getTestClient()
                self.__parsedConfig = obj_marvininit.getParsedConfig()
                self.__resultStream = obj_marvininit.getResultFile()
                self.__testRunner = nose.core.TextTestRunner(
                    stream=self.__resultStream,
                    descriptions=True,
                    verbosity=2,
                    config=self.conf)
                return SUCCESS
            return FAILED
        except Exception as e:
            self.__tcRunLogger.exception(
                ("=== Start Marvin failed: %s ===" % e))
            return FAILED

    def stopTest(self, test):
        """
        Currently used to record end time for tests
        """
        endTime = time.time()
        if self.__startTime:
            totTime = int(endTime - self.__startTime)
            self.__tcRunLogger.info(
                "TestCaseName: %s; Time Taken: %s Seconds; StartTime: %s; EndTime: %s; Result: %s"
                % (self.__testName, str(totTime),
                   str(time.ctime(self.__startTime)), str(
                       time.ctime(endTime)), self.__testResult))

    def _injectClients(self, test):
        setattr(test, "debug", self.__tcRunLogger.debug)
        setattr(test, "info", self.__tcRunLogger.info)
        setattr(test, "warn", self.__tcRunLogger.warning)
        setattr(test, "error", self.__tcRunLogger.error)
        setattr(test, "testClient", self.__testClient)
        setattr(test, "config", self.__parsedConfig)
        if self.__testClient.identifier is None:
            self.__testClient.identifier = self.__identifier
        setattr(test, "clstestclient", self.__testClient)
        if hasattr(test, "user"):
            # when the class-level attr applied. all test runs as 'user'
            self.__testClient.getUserApiClient(test.UserName, test.DomainName,
                                               test.AcctType)

    def finalize(self, result):
        self.__tcRunLogger.info('=== finalize does nothing!  ===')
Example #21
0
              "Valid Input Configuration File ===="
        exit(1)

    if (options.upload_iso is None) and (options.upload_tmpl is None):
        print "\n==== For uploading file: Please Specify a " \
              "HTTP path for file ===="
        exit(1)

    if (options.input) and not (os.path.isfile(options.input)):
        print "\n=== Invalid Input Config File Path, Please Check ==="
        exit(1)

    from marvin.marvinLog import MarvinLog
    from marvin.cloudstackTestClient import CSTestClient

    log_obj = MarvinLog("CSLogTemplates")
    cfg = configGenerator.getSetupConfig(options.input)
    log = cfg.logger
    ret = log_obj.createLogs("UploadTemplates", log)
    if ret != FAILED:
        log_folder_path = log_obj.getLogFolderPath()
        tc_run_logger = log_obj.getLogger()
    else:
        print "\n=== Log Creation Failed. Please Check ==="
        exit(1)

    obj_tc_client = CSTestClient(cfg.mgtSvr[0],
                                 cfg.dbSvr,
                                 logger=tc_run_logger)
    if obj_tc_client and obj_tc_client.createTestClient() == FAILED:
        print "\n=== TestClient Creation Failed ==="
Example #22
0
if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option("-i",
                      "--input",
                      action="store",
                      default="./datacenterCfg",
                      dest="input",
                      help="the path \
                      where the json config file generated, by default is \
                      ./datacenterCfg")

    (options, args) = parser.parse_args()
    from marvin.marvinLog import MarvinLog
    cfg = configGenerator.getSetupConfig(options.input)
    log_obj = MarvinLog("CSLog")
    tcRunLogger = log_obj.setLogHandler("/tmp/debug.log")
    deploy = deployDataCenters(cfg, tcRunLogger)
    deploy.deploy()
    """
    create = createStoragePool.createStoragePoolCmd()
    create.clusterid = 1
    create.podid = 2
    create.name = "fdffdf"
    create.url = "nfs://jfkdjf/fdkjfkd"
    create.zoneid = 2

    deploy = deployDataCenters("./datacenterCfg")
    deploy.loadCfg()
    deploy.apiClient.createStoragePool(create)
    """
Example #23
0
    '''
    if options.input is None and options.remove is None:
        print "\n==== For DeployDataCenter: Please Specify a " \
              "Valid Input Configuration File===="
        print "\n==== For DeleteDataCenters: Please Specify a " \
              "Valid Input Configuration File and DC Settings===="
        exit(1)
    '''
    Imports the Modules Required
    '''
    from marvin.marvinLog import MarvinLog
    from marvin.cloudstackTestClient import CSTestClient
    '''
    Step1: Create the Logger
    '''
    log_obj = MarvinLog("CSLog")
    cfg = configGenerator.getSetupConfig(options.input)
    log = cfg.logger

    ret = log_obj.createLogs("DeployDataCenter", log)
    if ret != FAILED:
        log_folder_path = log_obj.getLogFolderPath()
        tc_run_logger = log_obj.getLogger()
    else:
        print "\n===Log Creation Failed. Please Check==="
        exit(1)
    '''
    Step2 : Create Test Client
    '''
    obj_tc_client = CSTestClient(cfg.mgtSvr[0],
                                 cfg.dbSvr,
Example #24
0
    def test_create_marvin_log_with_default_name(self):
        marvin_log = MarvinLog()

        self.assertIsNotNone(marvin_log)
        self.assertEquals('marvin.marvinLog', marvin_log.getLogger().name)