~ubuntu-branches/ubuntu/trusty/cinder/trusty

« back to all changes in this revision

Viewing changes to cinder/tests/test_storwize_svc.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2013-03-16 09:30:20 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20130316093020-xnaqjbr18uhkti6l
Tags: 1:2013.1~rc1-0ubuntu1
[ Chuck Short ]
* debian/patches/fix-ubuntu-tests.patch: Dropped.
* debian/rules: Fix version number when building the testsuite. 
* debian/cinder-backup{.install, upstart, logroate}: Add cinder-backup
  service.
* debian/rules: Run the testsuite against PYTHONPATH.
* debian/control: Update build-depends and run-time depends.
  - Dropped python-glance not needed.
  - Dropped python-cheetah not needed.
  - Droped python-daemon not needed.
  - Dropped python-netaddr not needed.
  - Renamed python-oslo-config to python-oslo.config.
  - Added python-keystoneclient to depends.
  - Added python-swiftclient to depends.
 * debian/pydist-overrides: No longer needed.

[ James Page ]
* New upstream release candidate.
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org.
* d/cinder.conf: Set lock_path to /var/lock/cinder (default is not
  sensible).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
Tests for the IBM Storwize family and SVC volume driver.
25
25
"""
26
26
 
27
 
import mox
28
27
import random
29
28
import re
30
29
import socket
31
30
 
32
31
from cinder import context
33
32
from cinder import exception
34
 
from cinder import flags
35
33
from cinder.openstack.common import excutils
36
34
from cinder.openstack.common import log as logging
37
35
from cinder import test
40
38
from cinder.volume.drivers import storwize_svc
41
39
from cinder.volume import volume_types
42
40
 
43
 
FLAGS = flags.FLAGS
44
41
 
45
42
LOG = logging.getLogger(__name__)
46
43
 
213
210
            'unit',
214
211
            'easytier',
215
212
            'warning',
 
213
            'wwpn',
216
214
        ]
217
215
 
218
216
        # Handle the special case of lsnode which is a two-word command
474
472
 
475
473
    def _cmd_lsfabric(self, **kwargs):
476
474
        host_name = kwargs['host'] if 'host' in kwargs else None
 
475
        target_wwpn = kwargs['wwpn'] if 'wwpn' in kwargs else None
477
476
        host_infos = []
478
477
 
479
478
        for hk, hv in self._hosts_list.iteritems():
480
479
            if not host_name or hv['host_name'] == host_name:
481
480
                for mk, mv in self._mappings_list.iteritems():
482
481
                    if mv['host'] == hv['host_name']:
483
 
                        host_infos.append(hv)
484
 
                        break
 
482
                        if not target_wwpn or target_wwpn in hv['wwpns']:
 
483
                            host_infos.append(hv)
 
484
                            break
485
485
 
486
486
        if not len(host_infos):
487
487
            return ('', '')
497
497
                            host_info['host_name'], '', 'host'])
498
498
 
499
499
        if self._next_cmd_error['lsfabric'] == 'header_mismatch':
500
 
            rows[0].pop(2)
 
500
            rows[0].pop(0)
501
501
            self._next_cmd_error['lsfabric'] = ''
502
502
        if self._next_cmd_error['lsfabric'] == 'remove_field':
503
503
            for row in rows:
504
 
                row.pop(4)
 
504
                row.pop(0)
505
505
            self._next_cmd_error['lsfabric'] = ''
506
506
        return self._print_info_cmd(rows=rows, **kwargs)
507
507
 
1239
1239
        super(StorwizeSVCDriverTestCase, self).setUp()
1240
1240
        self.USESIM = True
1241
1241
        if self.USESIM:
 
1242
            self.driver = StorwizeSVCFakeDriver(
 
1243
                                configuration=conf.Configuration(None))
1242
1244
            self._def_flags = {'san_ip': 'hostname',
1243
1245
                               'san_login': 'user',
1244
1246
                               'san_password': 'pass',
1245
1247
                               'storwize_svc_flashcopy_timeout': 20,
1246
 
                               'storwize_svc_connection_protocol': 'iscsi',
 
1248
                               # Test ignore capitalization
 
1249
                               'storwize_svc_connection_protocol': 'iScSi',
1247
1250
                               'storwize_svc_multipath_enabled': False}
1248
1251
            self._host_name = 'storwize-svc-test'
1249
1252
            self._host_ip = '1.234.56.78'
1252
1255
                    str(random.randint(0, 9999999999999999)).zfill(16)]
1253
1256
            self._iscsi_name = ('test.initiator.%s' %
1254
1257
                                str(random.randint(10000, 99999)))
1255
 
            self._reset_flags()
1256
1258
            self.sim = StorwizeSVCManagementSimulator('volpool')
1257
1259
 
1258
 
            configuration = mox.MockObject(conf.Configuration)
1259
 
            configuration.san_is_local = False
1260
 
            configuration.append_config_values(mox.IgnoreArg())
1261
 
 
1262
 
            self.driver = StorwizeSVCFakeDriver(configuration=configuration)
1263
1260
            self.driver.set_fake_storage(self.sim)
1264
1261
        else:
 
1262
            self.driver = storwize_svc.StorwizeSVCDriver(
 
1263
                                configuration=conf.Configuration(None))
1265
1264
            self._def_flags = {'san_ip': '1.111.11.11',
1266
1265
                               'san_login': 'user',
1267
1266
                               'san_password': 'password',
1268
1267
                               'storwize_svc_volpool_name': 'openstack',
1269
 
                               'storwize_svc_connection_protocol': 'iscsi',
 
1268
                               # Test ignore capitalization
 
1269
                               'storwize_svc_connection_protocol': 'iScSi',
1270
1270
                               'storwize_svc_multipath_enabled': False,
1271
1271
                               'ssh_conn_timeout': 0}
1272
1272
            self._host_name = socket.gethostname()
1288
1288
                if l.startswith('InitiatorName='):
1289
1289
                    self._iscsi_name = l[l.index('=') + 1:].strip()
1290
1290
 
1291
 
            self._reset_flags()
1292
 
            self.driver = storwize_svc.StorwizeSVCDriver()
1293
 
 
 
1291
        self._reset_flags()
1294
1292
        self.driver.db = StorwizeSVCFakeDB()
1295
1293
        self.driver.do_setup(None)
1296
1294
        self.driver.check_for_setup_error()
1297
1295
        self.stubs.Set(storwize_svc.time, 'sleep', lambda s: None)
1298
1296
 
 
1297
    def _set_flag(self, flag, value):
 
1298
        group = self.driver.configuration.config_group
 
1299
        self.driver.configuration.set_override(flag, value, group)
 
1300
 
1299
1301
    def _reset_flags(self):
1300
 
        FLAGS.reset()
1301
 
        self.flags(**self._def_flags)
 
1302
        self.driver.configuration.local_conf.reset()
 
1303
        for k, v in self._def_flags.iteritems():
 
1304
            self._set_flag(k, v)
1302
1305
 
1303
1306
    def _assert_vol_exists(self, name, exists):
1304
1307
        is_vol_defined = self.driver._is_vdisk_defined(name)
1307
1310
    def test_storwize_svc_connectivity(self):
1308
1311
        # Make sure we detect if the pool doesn't exist
1309
1312
        no_exist_pool = 'i-dont-exist-%s' % random.randint(10000, 99999)
1310
 
        self.flags(storwize_svc_volpool_name=no_exist_pool)
 
1313
        self._set_flag('storwize_svc_volpool_name', no_exist_pool)
1311
1314
        self.assertRaises(exception.InvalidInput,
1312
1315
                          self.driver.do_setup, None)
1313
1316
        self._reset_flags()
1340
1343
                              self.driver.do_setup, None)
1341
1344
 
1342
1345
        # Check with bad parameters
1343
 
        self.flags(san_ip='')
1344
 
        self.assertRaises(exception.InvalidInput,
1345
 
                          self.driver.check_for_setup_error)
1346
 
        self._reset_flags()
1347
 
 
1348
 
        self.flags(san_password=None)
1349
 
        self.flags(san_private_key=None)
1350
 
        self.assertRaises(exception.InvalidInput,
1351
 
                          self.driver.check_for_setup_error)
1352
 
        self._reset_flags()
1353
 
 
1354
 
        self.flags(storwize_svc_vol_rsize=101)
1355
 
        self.assertRaises(exception.InvalidInput,
1356
 
                          self.driver.check_for_setup_error)
1357
 
        self._reset_flags()
1358
 
 
1359
 
        self.flags(storwize_svc_vol_warning=101)
1360
 
        self.assertRaises(exception.InvalidInput,
1361
 
                          self.driver.check_for_setup_error)
1362
 
        self._reset_flags()
1363
 
 
1364
 
        self.flags(storwize_svc_vol_grainsize=42)
1365
 
        self.assertRaises(exception.InvalidInput,
1366
 
                          self.driver.check_for_setup_error)
1367
 
        self._reset_flags()
1368
 
 
1369
 
        self.flags(storwize_svc_flashcopy_timeout=601)
1370
 
        self.assertRaises(exception.InvalidInput,
1371
 
                          self.driver.check_for_setup_error)
1372
 
        self._reset_flags()
1373
 
 
1374
 
        self.flags(storwize_svc_vol_compression=True)
1375
 
        self.flags(storwize_svc_vol_rsize=-1)
1376
 
        self.assertRaises(exception.InvalidInput,
1377
 
                          self.driver.check_for_setup_error)
1378
 
        self._reset_flags()
1379
 
 
1380
 
        self.flags(storwize_svc_connection_protocol='foo')
1381
 
        self.assertRaises(exception.InvalidInput,
1382
 
                          self.driver.check_for_setup_error)
1383
 
        self._reset_flags()
1384
 
 
1385
 
        self.flags(storwize_svc_connection_protocol='iscsi')
1386
 
        self.flags(storwize_svc_multipath_enabled=True)
 
1346
        self._set_flag('san_ip', '')
 
1347
        self.assertRaises(exception.InvalidInput,
 
1348
                          self.driver.check_for_setup_error)
 
1349
        self._reset_flags()
 
1350
 
 
1351
        self._set_flag('san_password', None)
 
1352
        self._set_flag('san_private_key', None)
 
1353
        self.assertRaises(exception.InvalidInput,
 
1354
                          self.driver.check_for_setup_error)
 
1355
        self._reset_flags()
 
1356
 
 
1357
        self._set_flag('storwize_svc_vol_rsize', 101)
 
1358
        self.assertRaises(exception.InvalidInput,
 
1359
                          self.driver.check_for_setup_error)
 
1360
        self._reset_flags()
 
1361
 
 
1362
        self._set_flag('storwize_svc_vol_warning', 101)
 
1363
        self.assertRaises(exception.InvalidInput,
 
1364
                          self.driver.check_for_setup_error)
 
1365
        self._reset_flags()
 
1366
 
 
1367
        self._set_flag('storwize_svc_vol_grainsize', 42)
 
1368
        self.assertRaises(exception.InvalidInput,
 
1369
                          self.driver.check_for_setup_error)
 
1370
        self._reset_flags()
 
1371
 
 
1372
        self._set_flag('storwize_svc_flashcopy_timeout', 601)
 
1373
        self.assertRaises(exception.InvalidInput,
 
1374
                          self.driver.check_for_setup_error)
 
1375
        self._reset_flags()
 
1376
 
 
1377
        self._set_flag('storwize_svc_vol_compression', True)
 
1378
        self._set_flag('storwize_svc_vol_rsize', -1)
 
1379
        self.assertRaises(exception.InvalidInput,
 
1380
                          self.driver.check_for_setup_error)
 
1381
        self._reset_flags()
 
1382
 
 
1383
        self._set_flag('storwize_svc_connection_protocol', 'foo')
 
1384
        self.assertRaises(exception.InvalidInput,
 
1385
                          self.driver.check_for_setup_error)
 
1386
        self._reset_flags()
 
1387
 
 
1388
        self._set_flag('storwize_svc_connection_protocol', 'iSCSI')
 
1389
        self._set_flag('storwize_svc_multipath_enabled', True)
1387
1390
        self.assertRaises(exception.InvalidInput,
1388
1391
                          self.driver.check_for_setup_error)
1389
1392
        self._reset_flags()
1390
1393
 
1391
1394
        if self.USESIM:
1392
1395
            self.sim.error_injection('lslicense', 'no_compression')
1393
 
            self.flags(storwize_svc_vol_compression=True)
 
1396
            self._set_flag('storwize_svc_vol_compression', True)
1394
1397
            self.driver.do_setup(None)
1395
1398
            self.assertRaises(exception.InvalidInput,
1396
1399
                              self.driver.check_for_setup_error)
1438
1441
        snap1 = self._generate_vol_info(vol1['name'], vol1['id'])
1439
1442
 
1440
1443
        # Test timeout and volume cleanup
1441
 
        self.flags(storwize_svc_flashcopy_timeout=1)
 
1444
        self._set_flag('storwize_svc_flashcopy_timeout', 1)
1442
1445
        self.assertRaises(exception.InvalidSnapshot,
1443
1446
                          self.driver.create_snapshot, snap1)
1444
1447
        self._assert_vol_exists(snap1['name'], False)
1555
1558
        attributes = self.driver._get_vdisk_attributes(volume['name'])
1556
1559
        attr_size = float(attributes['capacity']) / (1024 ** 3)  # bytes to GB
1557
1560
        self.assertEqual(attr_size, float(volume['size']))
1558
 
        pool = storwize_svc.FLAGS.storwize_svc_volpool_name
 
1561
        pool = self.driver.configuration.local_conf.storwize_svc_volpool_name
1559
1562
        self.assertEqual(attributes['mdisk_grp_name'], pool)
1560
1563
 
1561
1564
        # Try to create the volume again (should fail)
1611
1614
        for idx in range(len(opts_list)):
1612
1615
            attrs = self._create_test_vol(opts_list[idx])
1613
1616
            for k, v in chck_list[idx].iteritems():
1614
 
                print k + ' ' + v
1615
1617
                try:
1616
1618
                    if k[0] == '-':
1617
1619
                        k = k[1:]
1624
1626
 
1625
1627
    def test_storwize_svc_unicode_host_and_volume_names(self):
1626
1628
        # We'll check with iSCSI only - nothing protocol-dependednt here
1627
 
        self.flags(storwize_svc_connection_protocol='iscsi')
 
1629
        self._set_flag('storwize_svc_connection_protocol', 'iSCSI')
1628
1630
        self.driver.do_setup(None)
1629
1631
 
1630
1632
        rand_id = random.randint(10000, 99999)
1681
1683
 
1682
1684
        # Create volume types that we created
1683
1685
        types = {}
1684
 
        for protocol in ['fc', 'iscsi']:
1685
 
            opts = {'protocol': protocol}
 
1686
        for protocol in ['FC', 'iSCSI']:
 
1687
            opts = {'storage_protocol': '<in> ' + protocol}
1686
1688
            types[protocol] = volume_types.create(ctxt, protocol, opts)
1687
1689
 
1688
1690
        conn = {'initiator': self._iscsi_name,
1690
1692
                'host': self._host_name,
1691
1693
                'wwpns': self._host_wwpns}
1692
1694
 
1693
 
        for protocol in ['fc', 'iscsi']:
 
1695
        for protocol in ['FC', 'iSCSI']:
1694
1696
            volume1['volume_type_id'] = types[protocol]['id']
1695
1697
            volume2['volume_type_id'] = types[protocol]['id']
1696
1698
 
1697
1699
            # Check case where no hosts exist
1698
 
            ret = self.driver._get_host_from_connector(conn)
1699
 
            self.assertEqual(ret, None)
 
1700
            if self.USESIM:
 
1701
                ret = self.driver._get_host_from_connector(conn)
 
1702
                self.assertEqual(ret, None)
1700
1703
 
1701
1704
            # Make sure that the volumes have been created
1702
1705
            self._assert_vol_exists(volume1['name'], True)
1703
1706
            self._assert_vol_exists(volume2['name'], True)
1704
1707
 
1705
 
            # Check bad output from lsfabric
1706
 
            if protocol == 'fc' and self.USESIM:
1707
 
                for error in ['remove_field', 'header_mismatch']:
1708
 
                    self.sim.error_injection('lsfabric', error)
1709
 
                    self.assertRaises(exception.VolumeBackendAPIException,
1710
 
                                      self.driver.initialize_connection,
1711
 
                                      volume1, conn)
1712
 
                    host_name = self.driver._get_host_from_connector(conn)
1713
 
                    self.assertEqual(host_name, None)
1714
 
 
1715
1708
            # Initialize connection from the first volume to a host
1716
1709
            self.driver.initialize_connection(volume1, conn)
1717
1710
 
1723
1716
                              self.driver.delete_volume,
1724
1717
                              volume1)
1725
1718
 
 
1719
            # Check bad output from lsfabric for the 2nd volume
 
1720
            if protocol == 'FC' and self.USESIM:
 
1721
                for error in ['remove_field', 'header_mismatch']:
 
1722
                    self.sim.error_injection('lsfabric', error)
 
1723
                    self.assertRaises(exception.VolumeBackendAPIException,
 
1724
                                      self.driver.initialize_connection,
 
1725
                                      volume2, conn)
 
1726
 
1726
1727
            self.driver.terminate_connection(volume1, conn)
 
1728
            if self.USESIM:
 
1729
                host_name = self.driver._get_host_from_connector(conn)
 
1730
                self.assertEqual(host_name, None)
1727
1731
 
1728
1732
        # Check cases with no auth set for host
1729
1733
        if self.USESIM:
1733
1737
                           'ip': '11.11.11.11',
1734
1738
                           'host': 'host-%s' % case}
1735
1739
                self.sim._add_host_to_list(conn_na)
1736
 
                volume1['volume_type_id'] = types['iscsi']['id']
 
1740
                volume1['volume_type_id'] = types['iSCSI']['id']
1737
1741
                if case == 'no_info':
1738
1742
                    self.sim.error_injection('lsiscsiauth', 'no_info')
1739
1743
                self.driver.initialize_connection(volume1, conn_na)
1758
1762
        # Try to remove connection from host that doesn't exist (should fail)
1759
1763
        conn_no_exist = conn.copy()
1760
1764
        conn_no_exist['initiator'] = 'i_dont_exist'
1761
 
        conn_no_exist['wwpns'] = ['i_dont_exist']
 
1765
        conn_no_exist['wwpns'] = ['0000000000000000']
1762
1766
        self.assertRaises(exception.VolumeBackendAPIException,
1763
1767
                          self.driver.terminate_connection,
1764
1768
                          volume1,
1785
1789
        self._assert_vol_exists(volume2['name'], False)
1786
1790
 
1787
1791
        # Delete volume types that we created
1788
 
        for protocol in ['fc', 'iscsi']:
 
1792
        for protocol in ['FC', 'iSCSI']:
1789
1793
            volume_types.destroy(ctxt, types[protocol]['id'])
1790
1794
 
1791
1795
        # Check if our host still exists (it should not)
1874
1878
            self.fail('%s not less than or equal to %s' % (repr(a), repr(b)))
1875
1879
 
1876
1880
    def test_storwize_svc_get_volume_stats(self):
1877
 
        #first call,  no refresh, expect None
1878
1881
        stats = self.driver.get_volume_stats()
1879
 
        self.assertEqual(stats, {})
1880
 
 
1881
 
        #call with refresh
1882
 
        stats = self.driver.get_volume_stats(refresh=True)
1883
1882
        self.assertLessEqual(stats['free_capacity_gb'],
1884
1883
                             stats['total_capacity_gb'])
1885
1884
        if self.USESIM: