~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/fake.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-06-22 12:39:57 UTC
  • mfrom: (1.1.57)
  • Revision ID: package-import@ubuntu.com-20120622123957-hbzwg84nt9rqwg8r
Tags: 2012.2~f2~20120621.14517-0ubuntu1
[ Chuck Short ]
* New upstream version.

[ Adam Gandelman ]
* debian/rules: Temporarily disable test suite while blocking
  tests are investigated. 
* debian/patches/kombu_tests_timeout.patch: Dropped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
"""
52
52
 
53
53
 
54
 
import json
55
54
import random
56
55
import uuid
57
56
from xml.sax import saxutils
60
59
 
61
60
from nova import exception
62
61
from nova import log as logging
63
 
from nova import utils
 
62
from nova.openstack.common import jsonutils
 
63
from nova.openstack.common import timeutils
64
64
 
65
65
 
66
66
_CLASSES = ['host', 'network', 'session', 'pool', 'SR', 'VBD',
276
276
def _create_sr(table, obj):
277
277
    sr_type = obj[6]
278
278
    # Forces fake to support iscsi only
279
 
    if sr_type != 'iscsi':
 
279
    if sr_type != 'iscsi' and sr_type != 'nfs':
280
280
        raise Failure(['SR_UNKNOWN_DRIVER', sr_type])
281
281
    host_ref = _db_content['host'].keys()[0]
282
282
    sr_ref = _create_object(table, obj[2])
283
 
    vdi_ref = create_vdi('', sr_ref)
284
 
    pbd_ref = create_pbd('', host_ref, sr_ref, True)
285
 
    _db_content['SR'][sr_ref]['VDIs'] = [vdi_ref]
286
 
    _db_content['SR'][sr_ref]['PBDs'] = [pbd_ref]
287
 
    _db_content['VDI'][vdi_ref]['SR'] = sr_ref
288
 
    _db_content['PBD'][pbd_ref]['SR'] = sr_ref
 
283
    if sr_type == 'iscsi':
 
284
        vdi_ref = create_vdi('', sr_ref)
 
285
        pbd_ref = create_pbd('', host_ref, sr_ref, True)
 
286
        _db_content['SR'][sr_ref]['VDIs'] = [vdi_ref]
 
287
        _db_content['SR'][sr_ref]['PBDs'] = [pbd_ref]
 
288
        _db_content['VDI'][vdi_ref]['SR'] = sr_ref
 
289
        _db_content['PBD'][pbd_ref]['SR'] = sr_ref
289
290
    return sr_ref
290
291
 
291
292
 
337
338
    then these are rendered as a JSON list.  If it's given keyword
338
339
    arguments then these are rendered as a JSON dict."""
339
340
    arg = args or kwargs
340
 
    return json.dumps(arg)
 
341
    return jsonutils.dumps(arg)
341
342
 
342
343
 
343
344
class Failure(Exception):
475
476
        name_label = db_ref['name_label']
476
477
        read_only = db_ref['read_only']
477
478
        sharable = db_ref['sharable']
478
 
        vdi_ref = create_vdi(name_label, sr_ref, sharable=sharable,
479
 
                             read_only=read_only)
480
 
        return vdi_ref
 
479
        other_config = db_ref['other_config'].copy()
 
480
        return create_vdi(name_label, sr_ref, sharable=sharable,
 
481
                          read_only=read_only, other_config=other_config)
481
482
 
482
483
    def VDI_clone(self, _1, vdi_to_clone_ref):
483
484
        db_ref = _db_content['VDI'][vdi_to_clone_ref]
484
 
        name_label = db_ref['name_label']
485
 
        read_only = db_ref['read_only']
486
485
        sr_ref = db_ref['SR']
487
 
        sharable = db_ref['sharable']
488
 
        vdi_ref = create_vdi(name_label, sr_ref, sharable=sharable,
489
 
                             read_only=read_only)
490
 
        return vdi_ref
 
486
        return self.VDI_copy(_1, vdi_to_clone_ref, sr_ref)
491
487
 
492
488
    def host_compute_free_memory(self, _1, ref):
493
489
        #Always return 12GB available
515
511
        elif (plugin, method) == ('migration', 'transfer_vhd'):
516
512
            return ''
517
513
        elif (plugin, method) == ('xenhost', 'host_data'):
518
 
            return json.dumps({'host_memory': {'total': 10,
519
 
                                               'overhead': 20,
520
 
                                               'free': 30,
521
 
                                               'free-computed': 40}, })
 
514
            return jsonutils.dumps({'host_memory': {'total': 10,
 
515
                                                    'overhead': 20,
 
516
                                                    'free': 30,
 
517
                                                    'free-computed': 40}, })
522
518
        elif (plugin == 'xenhost' and method in ['host_reboot',
523
519
                                                 'host_startup',
524
520
                                                 'host_shutdown']):
525
 
            return json.dumps({"power_action": method[5:]})
 
521
            return jsonutils.dumps({"power_action": method[5:]})
526
522
        elif (plugin, method) == ('xenhost', 'set_host_enabled'):
527
523
            enabled = 'enabled' if _5.get('enabled') == 'true' else 'disabled'
528
 
            return json.dumps({"status": enabled})
 
524
            return jsonutils.dumps({"status": enabled})
529
525
        else:
530
526
            raise Exception('No simulation in host_call_plugin for %s,%s' %
531
527
                            (plugin, method))
744
740
        except Failure, exc:
745
741
            task['error_info'] = exc.details
746
742
            task['status'] = 'failed'
747
 
        task['finished'] = utils.utcnow()
 
743
        task['finished'] = timeutils.utcnow()
748
744
        return task_ref
749
745
 
750
746
    def _check_session(self, params):