~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_db_api.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130809101227-4n60fzcgra8dzk3d
Tags: 1:2013.1.3-0ubuntu1
* Resynchronize with stable/grizzly (89c7ee4) (LP: #1210447):
  - [8e6edd2] Bump stable/grizzly next version to 2013.1.3
  - [61fc529] attach quantum security group to an existing vm failed
    LP: 1189059
  - [60774bd] nova-compute fails to start if quantum is down LP: 1186357
  - [8e6d4b6] asymmetric routes in nova network with external gateway and
    routing_source_ip LP: 1182143
  - [8849413] Failed VM's not set to error state on exception LP: 1182056
  - [ef10eee] Double healing of info_cache with cells LP: 1180304
  - [7422d83] Can't log into  VM after powervm is resized LP: 1169848
  - [49ab0e8] stack trace when instance_actions extension can not find
    instance in GET LP: 1182867
  - [e71247c] nova service-list returns illegal result with non db service
    heartbeat LP: 1168861
  - [3f60606] Volume IO usage gets reset to 0 after a reboot / crash
    LP: 1169097
  - [19c443b] unused method  list_interfaces in vmware driver can be removed
    LP: 1187251
  - [a8dab9f] No cleanup done when file transfer fails with powervm driver
    LP: 1173017
  - [fc98015] nova consoleauth depends on Conductor Service LP: 1186123
  - [1066418] VMware drivers are no longer passing quantum port-id to
    vCenter LP: 1183452
  - [b92075c] nova net-list fails on empty list with Quantum backend
    LP: 1189976
  - [3ba31f2] Create VM with no networks with Quantum Gives SecurityGroups
    Exception LP: 1191044
  - [89150b2] Periodic ValueErrors when using qpid LP: 1185465
  - [0e0d615] Libvirt pre-Grizzly instances cannot be block migrated
    LP: 1185588
  - [27960ef] ZMQ ipc socket file is created using un-sanitized network
    input LP: 1122763
  - [265b868] cannot block migrate old style instances libvirt complains
    LP: 1175286
  - [008a68a] code logical error exists in vmwareapi vif.py  LP: 1177635
  - [378c045] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [48ddffe] Reboot of compute node breaks VMs with volumes LP: 1188326
  - [f427f01] Missing dashes from console-log LP: 1194032
  - [78ebf1a] network-create returns an internal error when network
    conflicts LP: 1158075
  - [767c850] Instance nics are reorder after reboot LP: 1187092
  - [0b45996] instance directory naming update to use uuid  LP: 1186944
  - [06cfad5] Disassociate failed dhcp fixed ip in deallocate_for_instance()
    method LP: 1180766
  - [cbcdfc5] Allow confirm_resize action on an instance in 'deleting'
    status LP: 1189391
  - [2563c44] aggregate_get_by_host returns aggregates from other hosts
    LP: 1201277
  - [109f3a9] nova libvirt driver requires iscsi initiator name regardless
    of using it in volume drivers LP: 1007084
  - [7f1c336] Host is always set to None in get_instance_nw_info(...)
    LP: 1194178
  - [1cf30a3] nova boot with colume should fail if the volume is already
    attached to another instance LP: 1166770
  - [9cb9361] Aggregate metadata filtering by key returns unrelated metadata
    LP: 1201283
  - [a61872b] Need clean up  ftp transfer faiure  in powervm driver
    LP: 1188884
  - [91bcd15] Race can cause soft deleted instance to be erased by mistake
    LP: 1186243
  - [c57fded] Nova fails to create a security group rule if ::0/0 is used as
    cidr LP: 1199943
  - [c698dd3] VMwareESXDriver and VMwareVCDriver report incorrect stat
    LP: 1180779
  - [e572faf] novnc fails when amqp_rpc_single_reply_queue=True LP: 1193031
  - [34ddd27] eventlet.monkey_patch() for spice and vnc proxy
  - [864837f] hypervisor_hostname not updated on evacuate LP: 1198284
  - [756a772] libvirt migrate/resize on shared storage can cause data loss
    LP: 1177247
  - [889b215] nova live-migration of volume-backed VM fails because of image
    is None LP: 1199811
  - [60712a4] VNC console does not work with VCDriver LP: 1178369
  - [e0aa0f5] metadata service throws error 500 when compute_driver is not
    set LP: 1184641
  - [340d337] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [8247dc8] Resource limit circumvention in Nova private flavors
    (CVE-2013-2256) LP: 1194093
  - [bd7e467] Denial of Service in Nova network source security groups
    (CVE-2013-4185) LP: 1184041
  - [c3fddb7] Resize a VM when a volume is attached fails LP: 1190364
  - [01edbaa] Hyper-V versions before 2012 are not properly recognized
    LP: 1203059
  - [b18818a] driver libvirt doesn't honor vif quota LP: 1185030
  - [798984d] config drive not visible to windows LP: 1155842
  - [d18ceb1] nova live-migration failed due to exception.MigrationError
    LP: 1171526
  - [1934dbc] vmware Hyper for nova vnc console url parameters error
    LP: 1172177
  - [89c7ee4] [OSSA 2013-023] Potential unsafe XML usage (CVE-2013-4179,
    CVE-2013-4202) LP: 1190229
* debian/rules: Clean new setuptools-git cruft.
* debian/control: Update Vcs fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1306
1306
 
1307
1307
    def test_aggregate_get_by_host(self):
1308
1308
        ctxt = context.get_admin_context()
1309
 
        values = {'name': 'fake_aggregate2'}
 
1309
        values2 = {'name': 'fake_aggregate2'}
 
1310
        values3 = {'name': 'fake_aggregate3'}
 
1311
        values4 = {'name': 'fake_aggregate4'}
 
1312
        values5 = {'name': 'fake_aggregate5'}
1310
1313
        a1 = _create_aggregate_with_hosts(context=ctxt)
1311
 
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
 
1314
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values2)
 
1315
        # a3 has no hosts and should not be in the results.
 
1316
        a3 = _create_aggregate(context=ctxt, values=values3)
 
1317
        # a4 has no matching hosts.
 
1318
        a4 = _create_aggregate_with_hosts(context=ctxt, values=values4,
 
1319
                hosts=['foo4.openstack.org'])
 
1320
        # a5 has no matching hosts after deleting the only matching host.
 
1321
        a5 = _create_aggregate_with_hosts(context=ctxt, values=values5,
 
1322
                hosts=['foo5.openstack.org', 'foo.openstack.org'])
 
1323
        db.aggregate_host_delete(ctxt, a5['id'],
 
1324
                                 'foo.openstack.org')
1312
1325
        r1 = db.aggregate_get_by_host(ctxt, 'foo.openstack.org')
1313
1326
        self.assertEqual([a1['id'], a2['id']], [x['id'] for x in r1])
1314
1327
 
1315
1328
    def test_aggregate_get_by_host_with_key(self):
1316
1329
        ctxt = context.get_admin_context()
1317
 
        values = {'name': 'fake_aggregate2'}
 
1330
        values2 = {'name': 'fake_aggregate2'}
 
1331
        values3 = {'name': 'fake_aggregate3'}
 
1332
        values4 = {'name': 'fake_aggregate4'}
1318
1333
        a1 = _create_aggregate_with_hosts(context=ctxt,
1319
1334
                                          metadata={'goodkey': 'good'})
1320
 
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
 
1335
        _create_aggregate_with_hosts(context=ctxt, values=values2)
 
1336
        _create_aggregate(context=ctxt, values=values3)
 
1337
        _create_aggregate_with_hosts(context=ctxt, values=values4,
 
1338
                hosts=['foo4.openstack.org'], metadata={'goodkey': 'bad'})
1321
1339
        # filter result by key
1322
1340
        r1 = db.aggregate_get_by_host(ctxt, 'foo.openstack.org', key='goodkey')
1323
1341
        self.assertEqual([a1['id']], [x['id'] for x in r1])
1336
1354
 
1337
1355
    def test_aggregate_metadata_get_by_host_with_key(self):
1338
1356
        ctxt = context.get_admin_context()
1339
 
        values = {'name': 'fake_aggregate2'}
1340
 
        values2 = {'name': 'fake_aggregate3'}
 
1357
        values2 = {'name': 'fake_aggregate12'}
 
1358
        values3 = {'name': 'fake_aggregate23'}
 
1359
        a2_hosts = ['foo1.openstack.org', 'foo2.openstack.org']
 
1360
        a2_metadata = {'good': 'value12', 'bad': 'badvalue12'}
 
1361
        a3_hosts = ['foo2.openstack.org', 'foo3.openstack.org']
 
1362
        a3_metadata = {'good': 'value23', 'bad': 'badvalue23'}
1341
1363
        a1 = _create_aggregate_with_hosts(context=ctxt)
1342
 
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
1343
 
        a3 = _create_aggregate_with_hosts(context=ctxt, values=values2,
1344
 
                hosts=['foo.openstack.org'], metadata={'good': 'value'})
1345
 
        r1 = db.aggregate_metadata_get_by_host(ctxt, 'foo.openstack.org',
 
1364
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values2,
 
1365
                hosts=a2_hosts, metadata=a2_metadata)
 
1366
        a3 = _create_aggregate_with_hosts(context=ctxt, values=values3,
 
1367
                hosts=a3_hosts, metadata=a3_metadata)
 
1368
        r1 = db.aggregate_metadata_get_by_host(ctxt, 'foo2.openstack.org',
1346
1369
                                               key='good')
1347
 
        self.assertEqual(r1['good'], set(['value']))
 
1370
        self.assertEqual(r1['good'], set(['value12', 'value23']))
1348
1371
        self.assertFalse('fake_key1' in r1)
 
1372
        self.assertFalse('bad' in r1)
1349
1373
        # Delete metadata
1350
1374
        db.aggregate_metadata_delete(ctxt, a3['id'], 'good')
1351
1375
        r2 = db.aggregate_metadata_get_by_host(ctxt, 'foo.openstack.org',
1354
1378
 
1355
1379
    def test_aggregate_host_get_by_metadata_key(self):
1356
1380
        ctxt = context.get_admin_context()
1357
 
        values = {'name': 'fake_aggregate2'}
1358
 
        values2 = {'name': 'fake_aggregate3'}
 
1381
        values2 = {'name': 'fake_aggregate12'}
 
1382
        values3 = {'name': 'fake_aggregate23'}
 
1383
        a2_hosts = ['foo1.openstack.org', 'foo2.openstack.org']
 
1384
        a2_metadata = {'good': 'value12', 'bad': 'badvalue12'}
 
1385
        a3_hosts = ['foo2.openstack.org', 'foo3.openstack.org']
 
1386
        a3_metadata = {'good': 'value23', 'bad': 'badvalue23'}
1359
1387
        a1 = _create_aggregate_with_hosts(context=ctxt)
1360
 
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
1361
 
        a3 = _create_aggregate_with_hosts(context=ctxt, values=values2,
1362
 
                hosts=['foo.openstack.org'], metadata={'good': 'value'})
 
1388
        a2 = _create_aggregate_with_hosts(context=ctxt, values=values2,
 
1389
                hosts=a2_hosts, metadata=a2_metadata)
 
1390
        a3 = _create_aggregate_with_hosts(context=ctxt, values=values3,
 
1391
                hosts=a3_hosts, metadata=a3_metadata)
1363
1392
        r1 = db.aggregate_host_get_by_metadata_key(ctxt, key='good')
1364
 
        self.assertEqual(r1, {'foo.openstack.org': set(['value'])})
 
1393
        self.assertEqual({
 
1394
            'foo1.openstack.org': set(['value12']),
 
1395
            'foo2.openstack.org': set(['value12', 'value23']),
 
1396
            'foo3.openstack.org': set(['value23']),
 
1397
        }, r1)
1365
1398
        self.assertFalse('fake_key1' in r1)
1366
1399
 
1367
1400
    def test_aggregate_get_by_host_not_found(self):
2047
2080
 
2048
2081
 
2049
2082
class VolumeUsageDBApiTestCase(test.TestCase):
 
2083
 
2050
2084
    def setUp(self):
2051
2085
        super(VolumeUsageDBApiTestCase, self).setUp()
2052
2086
        self.user_id = 'fake'
2053
2087
        self.project_id = 'fake'
2054
2088
        self.context = context.RequestContext(self.user_id, self.project_id)
2055
2089
 
 
2090
        self.useFixture(test.TimeOverride())
 
2091
 
2056
2092
    def test_vol_usage_update_no_totals_update(self):
2057
2093
        ctxt = context.get_admin_context()
2058
2094
        now = timeutils.utcnow()
2059
 
        timeutils.set_time_override(now)
2060
2095
        start_time = now - datetime.timedelta(seconds=10)
2061
2096
        refreshed_time = now - datetime.timedelta(seconds=5)
2062
2097
 
2064
2099
                                'curr_reads': 1000,
2065
2100
                                'curr_read_bytes': 2000,
2066
2101
                                'curr_writes': 3000,
2067
 
                                'curr_write_bytes': 4000},
 
2102
                                'curr_write_bytes': 4000,
 
2103
                                'tot_reads': 0,
 
2104
                                'tot_read_bytes': 0,
 
2105
                                'tot_writes': 0,
 
2106
                                'tot_write_bytes': 0},
2068
2107
                               {'volume_id': u'2',
2069
2108
                                'curr_reads': 100,
2070
2109
                                'curr_read_bytes': 200,
2071
2110
                                'curr_writes': 300,
2072
 
                                'curr_write_bytes': 400}]
 
2111
                                'curr_write_bytes': 400,
 
2112
                                'tot_reads': 0,
 
2113
                                'tot_read_bytes': 0,
 
2114
                                'tot_writes': 0,
 
2115
                                'tot_write_bytes': 0}]
2073
2116
 
2074
2117
        def _compare(vol_usage, expected):
2075
2118
            for key, value in expected.items():
2092
2135
        self.assertEqual(len(vol_usages), 2)
2093
2136
        _compare(vol_usages[0], expected_vol_usages[0])
2094
2137
        _compare(vol_usages[1], expected_vol_usages[1])
2095
 
        timeutils.clear_time_override()
2096
2138
 
2097
2139
    def test_vol_usage_update_totals_update(self):
2098
2140
        ctxt = context.get_admin_context()
2099
2141
        now = timeutils.utcnow()
2100
 
        timeutils.set_time_override(now)
2101
2142
        start_time = now - datetime.timedelta(seconds=10)
 
2143
 
 
2144
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=100, rd_bytes=200,
 
2145
                                        wr_req=300, wr_bytes=400,
 
2146
                                        instance_id=1)
 
2147
        current_usage = db.vol_get_usage_by_time(ctxt, start_time)[0]
 
2148
        self.assertEqual(current_usage['tot_reads'], 0)
 
2149
        self.assertEqual(current_usage['curr_reads'], 100)
 
2150
 
 
2151
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=200, rd_bytes=300,
 
2152
                                        wr_req=400, wr_bytes=500,
 
2153
                                        instance_id=1,
 
2154
                                        update_totals=True)
 
2155
        current_usage = db.vol_get_usage_by_time(ctxt, start_time)[0]
 
2156
        self.assertEqual(current_usage['tot_reads'], 200)
 
2157
        self.assertEqual(current_usage['curr_reads'], 0)
 
2158
 
 
2159
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=300, rd_bytes=400,
 
2160
                                        wr_req=500, wr_bytes=600,
 
2161
                                        instance_id=1)
 
2162
        current_usage = db.vol_get_usage_by_time(ctxt, start_time)[0]
 
2163
        self.assertEqual(current_usage['tot_reads'], 200)
 
2164
        self.assertEqual(current_usage['curr_reads'], 300)
 
2165
 
 
2166
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=400, rd_bytes=500,
 
2167
                                        wr_req=600, wr_bytes=700,
 
2168
                                        instance_id=1,
 
2169
                                        update_totals=True)
 
2170
 
 
2171
        vol_usages = db.vol_get_usage_by_time(ctxt, start_time)
 
2172
 
2102
2173
        expected_vol_usages = {'volume_id': u'1',
2103
2174
                               'tot_reads': 600,
2104
2175
                               'tot_read_bytes': 800,
2109
2180
                               'curr_writes': 0,
2110
2181
                               'curr_write_bytes': 0}
2111
2182
 
2112
 
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=100, rd_bytes=200,
2113
 
                                        wr_req=300, wr_bytes=400,
2114
 
                                        instance_id=1)
2115
 
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=200, rd_bytes=300,
2116
 
                                        wr_req=400, wr_bytes=500,
2117
 
                                        instance_id=1,
2118
 
                                        update_totals=True)
2119
 
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=300, rd_bytes=400,
2120
 
                                        wr_req=500, wr_bytes=600,
2121
 
                                        instance_id=1)
2122
 
        vol_usage = db.vol_usage_update(ctxt, 1, rd_req=400, rd_bytes=500,
2123
 
                                        wr_req=600, wr_bytes=700,
2124
 
                                        instance_id=1,
2125
 
                                        update_totals=True)
2126
 
 
2127
 
        vol_usages = db.vol_get_usage_by_time(ctxt, start_time)
2128
 
 
2129
2183
        self.assertEquals(1, len(vol_usages))
2130
2184
        for key, value in expected_vol_usages.items():
2131
2185
            self.assertEqual(vol_usages[0][key], value)
2132
 
        timeutils.clear_time_override()
 
2186
 
 
2187
    def test_vol_usage_update_when_blockdevicestats_reset(self):
 
2188
        ctxt = context.get_admin_context()
 
2189
        now = timeutils.utcnow()
 
2190
        start_time = now - datetime.timedelta(seconds=10)
 
2191
 
 
2192
        vol_usages = db.vol_get_usage_by_time(ctxt, start_time)
 
2193
        self.assertEqual(len(vol_usages), 0)
 
2194
 
 
2195
        db.vol_usage_update(ctxt, 1,
 
2196
                            rd_req=10000, rd_bytes=20000,
 
2197
                            wr_req=30000, wr_bytes=40000,
 
2198
                            instance_id=1)
 
2199
 
 
2200
        # Instance rebooted or crashed. block device stats were reset and are
 
2201
        # less then the previous values
 
2202
        db.vol_usage_update(ctxt, 1,
 
2203
                            rd_req=100, rd_bytes=200,
 
2204
                            wr_req=300, wr_bytes=400,
 
2205
                            instance_id=1)
 
2206
 
 
2207
        db.vol_usage_update(ctxt, 1,
 
2208
                            rd_req=200, rd_bytes=300,
 
2209
                            wr_req=400, wr_bytes=500,
 
2210
                            instance_id=1)
 
2211
 
 
2212
        vol_usage = db.vol_get_usage_by_time(ctxt, start_time)[0]
 
2213
        expected_vol_usage = {'volume_id': u'1',
 
2214
                              'curr_reads': 200,
 
2215
                              'curr_read_bytes': 300,
 
2216
                              'curr_writes': 400,
 
2217
                              'curr_write_bytes': 500,
 
2218
                              'tot_reads': 10000,
 
2219
                              'tot_read_bytes': 20000,
 
2220
                              'tot_writes': 30000,
 
2221
                              'tot_write_bytes': 40000}
 
2222
        for key, value in expected_vol_usage.items():
 
2223
            self.assertEqual(vol_usage[key], value, key)
 
2224
 
 
2225
    def test_vol_usage_update_totals_update_when_blockdevicestats_reset(self):
 
2226
        # This is unlikely to happen, but could when a volume is detached
 
2227
        # right after a instance has rebooted / recovered and before
 
2228
        # the system polled and updated the volume usage cache table.
 
2229
        ctxt = context.get_admin_context()
 
2230
        now = timeutils.utcnow()
 
2231
        start_time = now - datetime.timedelta(seconds=10)
 
2232
 
 
2233
        vol_usages = db.vol_get_usage_by_time(ctxt, start_time)
 
2234
        self.assertEqual(len(vol_usages), 0)
 
2235
 
 
2236
        db.vol_usage_update(ctxt, 1,
 
2237
                            rd_req=10000, rd_bytes=20000,
 
2238
                            wr_req=30000, wr_bytes=40000,
 
2239
                            instance_id=1)
 
2240
 
 
2241
        # Instance rebooted or crashed. block device stats were reset and are
 
2242
        # less then the previous values
 
2243
        db.vol_usage_update(ctxt, 1,
 
2244
                            rd_req=100, rd_bytes=200,
 
2245
                            wr_req=300, wr_bytes=400,
 
2246
                            instance_id=1,
 
2247
                            update_totals=True)
 
2248
 
 
2249
        vol_usage = db.vol_get_usage_by_time(ctxt, start_time)[0]
 
2250
        expected_vol_usage = {'volume_id': u'1',
 
2251
                              'curr_reads': 0,
 
2252
                              'curr_read_bytes': 0,
 
2253
                              'curr_writes': 0,
 
2254
                              'curr_write_bytes': 0,
 
2255
                              'tot_reads': 10100,
 
2256
                              'tot_read_bytes': 20200,
 
2257
                              'tot_writes': 30300,
 
2258
                              'tot_write_bytes': 40400}
 
2259
        for key, value in expected_vol_usage.items():
 
2260
            self.assertEqual(vol_usage[key], value, key)
2133
2261
 
2134
2262
 
2135
2263
class TaskLogTestCase(test.TestCase):