Beispiel #1
0
    def test_action_delete(self):
        CommandRunner.CommandRunner._getStatusOutputOrRetry = Mock(return_value=(255, """
Error: There are no entries matching your query."""))

        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetAppCluster('localhost', 'jay', '/foo/bar',
                                             '/netapp/volume', 'namespace',
                                             'initiatorGroup', 'snapshotPrefix'))
        assert (0, '') == lun._execute_action('delete')
Beispiel #2
0
    def test_action_check(self):
        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetApp7Mode('localhost', 'jay', '/foo/bar',
                                           '/netapp/volume', 'namespace',
                                           'initiatorGroup', 'snapshotPrefix'))

        lun._runCommand = Mock(return_value=(0, 'success'))
        assert (0, 'success') == lun._execute_action('check')

        lun._runCommand = Mock(return_value=(1, 'failure'))
        assert (1, 'failure') == lun._execute_action('check')
Beispiel #3
0
 def test_action_not_defined(self):
     lun = LUN('123', proxy=Backend())
     for action in Backend.lun_backend_cmd_mapping.keys():
         # This doesn't work for some reason.
         #self.assertRaises(SystemExit, lun._execute_action(action))
         try:
             lun._execute_action(action)
         except SystemExit:
             pass
         else:
             self.fail('Should have raised SystemExit')
Beispiel #4
0
    def test_action_snapshot_failure_retry(self):
        PORTAL = 'localhost'

        status_output = (255, """
Error: command failed: Snapshot operation not allowed due to clones backed by
snapshots. Try again after sometime""")

        CommandRunner.CommandRunner._getStatusOutput = Mock(return_value=status_output)

        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetAppCluster(PORTAL, 'jay', '/foo/bar',
                                             '/netapp/volume', 'namespace',
                                             'initiatorGroup', 'snapshotPrefix'))
        lun.associatedLUN = Mock()
        lun.associatedLUN.getUuid = Mock(return_value='foo')
        assert (255, '') == lun._execute_action('snapshot')
        assert (NUMBER_OF_RETRIES + 1) == CommandRunner.CommandRunner._getStatusOutput.call_count
Beispiel #5
0
    def test_action_snapshot_failure(self):
        PORTAL = 'localhost'

        def side_effect(action):
            if action == 'snapshot':
                return (255, """Error: command failed: The Snapshot(tm) copy name already exists""")
            elif action == 'clone':
                return (255, """Error: command failed: Clone start failed: Clone operation failed to start:
Clone file exists.""")

        CommandRunner.CommandRunner._getStatusOutputOrRetry = Mock(side_effect=side_effect)

        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetAppCluster(PORTAL, 'jay', '/foo/bar',
                                             '/netapp/volume', 'namespace',
                                             'initiatorGroup', 'snapshotPrefix'))
        lun.associatedLUN = Mock()
        lun.associatedLUN.getUuid = Mock(return_value='foo')
        assert (255, '') == lun._execute_action('snapshot')
Beispiel #6
0
    def test_action_getturl_failure(self):
        IQN = 'iqn.1992-08.com.netapp:sn.307fb4db630d11e38ca5123478563412:vs.19'
        PORTAL = 'localhost'

        def side_effect(action):
            if action == 'get_target':
                return (0, """vserver  target-name
-------- ----------------------------------------------------------------
hniscsi1 %s
    """ % IQN)
            elif action == 'get_lun':
                return (255, """There are no entries matching your query.""")

        CommandRunner.CommandRunner._getStatusOutputOrRetry = Mock(side_effect=side_effect)

        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetAppCluster(PORTAL, 'jay', '/foo/bar',
                                             '/netapp/volume', 'namespace',
                                             'initiatorGroup', 'snapshotPrefix'))
        status, _ = lun._execute_action('getturl')
        assert 255 == status
Beispiel #7
0
    def test_action_getturl_success(self):
        IQN = 'iqn.1992-08.com.netapp:sn.307fb4db630d11e38ca5123478563412:vs.19'
        LUN_ID = '123'
        PORTAL = 'localhost'

        def side_effect(action):
            if action == 'get_target':
                return (0, """vserver  target-name
-------- ----------------------------------------------------------------
hniscsi1 %s
    """ % IQN)
            elif action == 'get_lun':
                return (0, """ABC: abc
LUN ID: %s""" % LUN_ID)

        CommandRunner.CommandRunner._getStatusOutputOrRetry = Mock(side_effect=side_effect)

        from stratuslab.pdiskbackend.LUN import LUN
        lun = LUN('123', proxy=NetAppCluster(PORTAL, 'jay', '/foo/bar',
                                             '/netapp/volume', 'namespace',
                                             'initiatorGroup', 'snapshotPrefix'))
        turl = 'iscsi://%s:3260/%s:%s' % (PORTAL, IQN, LUN_ID)
        assert (0, turl) == lun._execute_action('getturl')
Beispiel #8
0
    if options.action:
        print_detail("Invalid action requested (%s)\n" % options.action)
    else:
        print_detail("No action specified\n")
    parser.print_help()
    abort("")

backend_proxy = PdiskBackendProxyFactory.createBackendProxy(ch)

# Execute requested action

status = 0

if options.action == 'check':
    print_detail("Checking LUN existence...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    status = lun.check()
elif options.action == 'create':
    print_detail("Creating LUN...", 1)
    lun = LUN(args[0], size=args[1], proxy=backend_proxy)
    status = lun.create()
elif options.action == 'delete':
    print_detail("Deleting LUN...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    status = lun.delete()
elif options.action == 'getturl':
    print_detail("Returning Transport URL...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    turl = lun.getTurl()
    # If an error occured, it has already been signaled.
    # If it succeeds, rebasedLUN should always be defined...
    if options.action:
        print_detail("Invalid action requested (%s)\n" % options.action)
    else:
        print_detail("No action specified\n")
    parser.print_help()
    abort("")

backend_proxy = PdiskBackendProxyFactory.createBackendProxy(ch)

# Execute requested action

status = 0

if options.action == 'check':
    print_detail("Checking LUN existence...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    status = lun.check()
elif options.action == 'create':
    print_detail("Creating LUN...", 1)
    lun = LUN(args[0], size=args[1], proxy=backend_proxy)
    status = lun.create()
elif options.action == 'delete':
    print_detail("Deleting LUN...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    status = lun.delete()
elif options.action == 'getturl' :
    print_detail("Returning Transport URL...", 1)
    lun = LUN(args[0], proxy=backend_proxy)
    turl = lun.getTurl()
    # If an error occured, it has already been signaled.
    # If it succeeds, rebasedLUN should always be defined...