예제 #1
0
    def create_storage_group(cls, testObject, redfishConfig, lun, volume, access, ports, initiators):

        command = 'create storagegroup lun=\"' + lun + '\"' + ' volume=' + volume + ' access=' + access + ' ports=' + ports + ' initiators=' + initiators
        RedfishCommand.execute(redfishConfig, command)

        # Validate that the StorageGroup exists
        url = RedfishSystem.get_uri(redfishConfig, 'StorageGroups')
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        cls.test_link_status(testObject, link, url)
        membersCount = JsonExtract.get_value(link.jsonData, None, '*****@*****.**', 1)
        testObject.assertGreaterEqual(membersCount, 1, 'StorageGroups [email protected], expected {}, received {}'.format(1, membersCount))

        odataIds = JsonExtract.get_values(link.jsonData, "@odata.id")

        # Don't include the main @odata.id for the Collection
        if (url[-1] == '/'):
            url = url[:-1]

        if (len(odataIds) > 0):
            odataIds.remove(url)        

        # Test name
        url = odataIds[0]
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        testObject.assertTrue(link.valid, 'StorageGroup link valid for URL ({})'.format(url))

        name = JsonExtract.get_value(link.jsonData, None, 'Name', 1)
        words = name.split('_')
        testObject.assertEqual(2, len(words), 'StorageGroup Name error, expected {}, received {}'.format(2, len(words)))
        volumeId = words[0]
        testObject.assertEqual(volume, volumeId, 'StorageGroup Volume Name error, expected {}, received {}'.format(volume, volumeId))
예제 #2
0
    def create_volume_paged(cls, testObject, redfishConfig, desiredName, poolName, size):

        command = 'create volume name=' + desiredName + ' size=' + str(size) + ' pool=' + poolName
        RedfishCommand.execute(redfishConfig, command)

        # Validate that the volume exists
        url = RedfishSystem.get_uri(redfishConfig, 'Volumes')
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        cls.test_link_status(testObject, link, url)
        membersCount = JsonExtract.get_value(link.jsonData, None, '*****@*****.**', 1)
        testObject.assertEqual(membersCount, 1, 'Volumes [email protected], expected {}, received {}'.format(1, membersCount))

        odataIds = JsonExtract.get_values(link.jsonData, "@odata.id")

        # Don't include the main @odata.id for the Collection
        if (url[-1] == '/'):
            url = url[:-1]

        if (len(odataIds) > 0):
            odataIds.remove(url)        

        # Test name and size
        url = odataIds[0]
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        testObject.assertTrue(link.valid, 'Volume link valid for URL ({})'.format(url))
        name = JsonExtract.get_value(link.jsonData, None, 'Name', 1)
        testObject.assertEqual(name, desiredName, 'Volume name error, expected {}, received {}'.format(desiredName, name))
        capacity = JsonExtract.get_value(link.jsonData, None, 'CapacityBytes', 1)
        testObject.assertLessEqual(capacity, size, 'Volume size error, expected {}, received {}'.format(size, capacity))
예제 #3
0
    def delete_volume(cls, testObject, redfishConfig, desiredName):

        # Delete Volume
        RedfishCommand.execute(redfishConfig, 'delete volumes ' + desiredName)

        time.sleep(config.sleepTimeAfterDelete)

        url = RedfishSystem.get_uri(redfishConfig, 'Volumes')
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        cls.test_link_status(testObject, link, url)
        membersCount = JsonExtract.get_value(link.jsonData, None, '*****@*****.**', 1)
        testObject.assertEqual(membersCount, 0, 'Volumes [email protected], expected {}, received {}'.format(0, membersCount))
예제 #4
0
    def delete_pool(cls, testObject, redfishConfig, poolName):

        # Remove Pool A and the disk group
        RedfishCommand.execute(redfishConfig, 'delete pools ' + poolName)

        time.sleep(config.sleepTimeAfterDelete)

        url = RedfishSystem.get_uri(redfishConfig, 'StoragePools')
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        cls.test_link_status(testObject, link, url)
        membersCount = JsonExtract.get_value(link.jsonData, None, '*****@*****.**', 1)
        testObject.assertEqual(membersCount, 0, 'StoragePools [email protected], expected {}, received {}'.format(0, membersCount))
예제 #5
0
    def cmdloop(self, redfishConfig, prompt='redfish'):

        while 1:
            try:
                print('')
                sys.stdout.write('({}) '.format(prompt))
                sys.stdout.flush()
                line = sys.stdin.readline().strip()

            except KeyboardInterrupt:
                break

            if not line:
                if (redfishConfig.get_bool('entertoexit')):
                    break

            elif (line == 'exit' or line == 'quit'):
                break

            elif (line.startswith('alias')):
                # Add the new alias to the dictionary
                words = line.split(' ')
                if (len(words) == 3):
                    alias = words[1]
                    original = words[2]
                    Trace.log(
                        TraceLevel.INFO,
                        '   ++ CFG: replacing ({}) with the alias ({})'.format(
                            alias, original))
                    self.aliases[alias] = original
                else:
                    Trace.log(TraceLevel.INFO,
                              '   ++ usage: alias <new> <original>')

            elif (line.startswith('!')):
                Trace.log(TraceLevel.TRACE,
                          '   CFG: [{0: >3}] {1}'.format(len(line), line))
                redfishConfig.execute(line)

            else:
                Trace.log(TraceLevel.TRACE, '>> PROCESS line={}'.format(line))
                # Check for the use of any alias
                words = line.split(' ')
                if (len(words) > 1):
                    if (words[0] in self.aliases):
                        line = line.replace(words[0], self.aliases[words[0]],
                                            1)

                Trace.log(TraceLevel.TRACE,
                          '   CMD: [{0: >3}] {1}'.format(len(line), line))
                RedfishCommand.execute(redfishConfig, line)
예제 #6
0
    def execute_script(cls, redfishConfig, scriptfile):

        Trace.log(TraceLevel.INFO, '')
        Trace.log(
            TraceLevel.INFO,
            '[] Execute Redfish API script file ({})...'.format(scriptfile))

        # Run script mode
        if (path.exists(scriptfile) == False):
            Trace.log(
                TraceLevel.ERROR,
                'Redfish API script file ({}) does not exist!'.format(
                    scriptfile))
            return (-1)

        lineCount = 0

        with open(scriptfile, 'r') as fileHandle:
            for line in fileHandle:

                line = line.strip()

                if (len(line) < 2 or line.startswith('#')):
                    # Skip comments
                    lineCount += 1
                    Trace.log(TraceLevel.TRACE,
                              '   CMT: [{0: >3}] {1}'.format(len(line), line))

                elif (line.startswith('!')):
                    lineCount += 1
                    Trace.log(TraceLevel.TRACE,
                              '   CFG: [{0: >3}] {1}'.format(len(line), line))
                    redfishConfig.execute(line)

                else:
                    lineCount += 1

                    if (redfishConfig.get_value('annotate') == 'yes'):
                        print('')
                        print('=' * 80)
                        print('= LINE[{0}] {1}'.format(lineCount, line))
                        print('=' * 80)

                    Trace.log(TraceLevel.TRACE,
                              '   CMD: [{0: >3}] {1}'.format(len(line), line))
                    RedfishCommand.execute(redfishConfig, line)

        return (lineCount)
예제 #7
0
    def create_diskgroup_paged(cls, testObject, redfishConfig, desiredName, poolName, driveCount, raidLevel):

        # Create a disk group
        command = 'create diskgroup name=' + desiredName + ' disks='
        while driveCount > 0:
            drive = RedfishSystem.get_next_available_drive(redfishConfig)
            command = command + drive['number']
            driveCount -= 1
            if driveCount:
                command = command + ','

        command = command + ' pool=' + poolName + ' level=' + raidLevel
        RedfishCommand.execute(redfishConfig, command)

        # Validate that the disk group and Pool exist
        url = RedfishSystem.get_uri(redfishConfig, 'StoragePools')
        link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
        cls.test_link_status(testObject, link, url)
        membersCount = JsonExtract.get_value(link.jsonData, None, '*****@*****.**', 1)
        testObject.assertEqual(membersCount, 2, 'StoragePools [email protected], expected {}, received {}'.format(2, membersCount))

        odataIds = JsonExtract.get_values(link.jsonData, "@odata.id")

        # Don't include the main @odata.id for the Collection
        if (url[-1] == '/'):
            url = url[:-1]

        if (len(odataIds) > 0):
            odataIds.remove(url)        

        for url in odataIds: 
            link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'GET', True, None)
            testObject.assertTrue(link.valid, 'StoragePool link valid for URL ({})'.format(url))

            description = JsonExtract.get_value(link.jsonData, None, 'Description', 1)
            name = JsonExtract.get_value(link.jsonData, None, 'Name', 1)

            if description == 'DiskGroup':
                testObject.assertEqual(name, desiredName, 'StoragePool name error, expected {}, received {}'.format(desiredName, name))
            elif description == 'Pool':
                testObject.assertEqual(name, poolName, 'StoragePool name error, expected {}, received {}'.format(poolName, name))
예제 #8
0
    def test_links(self):
        Trace.log(
            TraceLevel.VERBOSE, '>> Run {}.{}:{}'.format(
                type(self).__name__,
                sys._getframe().f_code.co_name,
                sys._getframe().f_lineno))
        url = self.versionUrl
        link = UrlAccess.process_request(self.redfishConfig, UrlStatus(url),
                                         'GET', False, None)
        TestSupport.test_link_status(self, link, url)

        RedfishCommand.execute(self.redfishConfig, 'create session')

        odataIds = JsonExtract.get_values(link.jsonData, "@odata.id")
        for url in odataIds:
            link = UrlAccess.process_request(self.redfishConfig,
                                             UrlStatus(url), 'GET', True, None)
            self.assertTrue(link.valid, 'Link valid for URL ({})'.format(url))

        # Delete any current active session
        sessionId = Label.decode(config.sessionIdVariable)
        if sessionId is not None:
            RedfishCommand.execute(self.redfishConfig,
                                   f'delete sessions {sessionId}')
예제 #9
0
 def tearDownClass(cls):
     # Delete any current active session
     sessionId = Label.decode(config.sessionIdVariable)
     if sessionId is not None:
         RedfishCommand.execute(cls.redfishConfig,
                                f'delete sessions {sessionId}')
예제 #10
0
 def setUpClass(cls):
     cls.redfishConfig = RedfishConfig(Label.decode(config.sessionConfig))
     RedfishCommand.execute(cls.redfishConfig, 'create session')
     cls.systemInitialized = RedfishSystem.initialize_system(
         cls.redfishConfig)
예제 #11
0
        help=
        'Set the trace level (4, 5, 6, or 7) INFO=4, VERBOSE=5, DEBUG=5, TRACE=6',
        nargs='?',
        const=1,
        type=int)

    args = parser.parse_args()

    # Load configuration settings, which can be overwritten at the command line or in a script file
    redfishConfig = RedfishConfig(config.defaultConfigFile if args.config ==
                                  None else args.config)

    if (args.tracelevel != None):
        redfishConfig.update('trace', args.tracelevel)

    if (args.scriptfile == None):
        # Run interactive mode
        ri = RedfishInteractive()
        ri.execute(redfishConfig)
    else:
        # Run script mode
        returncode = RedfishScript.execute_script(redfishConfig,
                                                  args.scriptfile)

    # Before existing, delete any current active session
    sessionId = Label.decode(config.sessionIdVariable)
    if sessionId is not None:
        RedfishCommand.execute(redfishConfig, f'delete sessions {sessionId}')

    sys.exit(returncode)