Ejemplo n.º 1
0
    def __init__(self):
        super(MultiScheduler, self).__init__()
        compute_driver = utils.import_object(FLAGS.compute_scheduler_driver)
        volume_driver = utils.import_object(FLAGS.volume_scheduler_driver)

        self.drivers = {'compute': compute_driver,
                        'volume': volume_driver}
Ejemplo n.º 2
0
 def setUp(self):
     super(VolumeTestCase, self).setUp()
     self.compute = utils.import_object(FLAGS.compute_manager)
     self.flags(connection_type='fake')
     self.volume = utils.import_object(FLAGS.volume_manager)
     self.context = context.get_admin_context()
     self.instance_id = db.instance_create(self.context, {})['id']
Ejemplo n.º 3
0
 def setUp(self):
     super(VolumeTestCase, self).setUp()
     self.compute = utils.import_object(FLAGS.compute_manager)
     self.flags(connection_type='fake')
     self.volume = utils.import_object(FLAGS.volume_manager)
     self.context = context.get_admin_context()
     self.instance_id = db.instance_create(self.context, {})['id']
Ejemplo n.º 4
0
    def __init__(self, vsa_driver=None, *args, **kwargs):
        if not vsa_driver:
            vsa_driver = FLAGS.vsa_driver
        self.driver = utils.import_object(vsa_driver)
        self.compute_manager = utils.import_object(FLAGS.compute_manager)

        self.compute_api = compute.API()
        self.volume_api = volume.API()
        self.vsa_api = vsa.API()

        if FLAGS.vsa_ec2_user_id is None or \
           FLAGS.vsa_ec2_access_key is None:
            raise exception.VSAEngineAccessParamNotFound()

        super(VsaManager, self).__init__(*args, **kwargs)
Ejemplo n.º 5
0
    def __init__(self, vsa_driver=None, *args, **kwargs):
        if not vsa_driver:
            vsa_driver = FLAGS.vsa_driver
        self.driver = utils.import_object(vsa_driver)
        self.compute_manager = utils.import_object(FLAGS.compute_manager)

        self.compute_api = compute.API()
        self.volume_api = volume.API()
        self.vsa_api = vsa.API()

        if FLAGS.vsa_ec2_user_id is None or \
           FLAGS.vsa_ec2_access_key is None:
            raise exception.VSAEngineAccessParamNotFound()

        super(VsaManager, self).__init__(*args, **kwargs)
Ejemplo n.º 6
0
    def setUp(self):
        super(AdminApiTestCase, self).setUp()
        self.flags(connection_type='fake')

        # set up our cloud
        self.api = admin.AdminController()

        # set up services
        self.compute = self.start_service('compute')
        self.scheduter = self.start_service('scheduler')
        self.network = self.start_service('network')
        self.volume = self.start_service('volume')
        self.image_service = utils.import_object(FLAGS.image_service)

        self.user_id = 'admin'
        self.project_id = 'admin'
        self.context = context.RequestContext(self.user_id,
                                              self.project_id,
                                              is_admin=True)

        def fake_show(meh, context, id):
            return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
                    'type': 'machine', 'image_state': 'available'}}

        self.stubs.Set(fake._FakeImageService, 'show', fake_show)
        self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show)

        # NOTE(comstud): Make 'cast' behave like a 'call' which will
        # ensure that operations complete
        self.stubs.Set(rpc, 'cast', rpc.call)
Ejemplo n.º 7
0
 def setUp(self):
     super(XenAPIVMTestCase, self).setUp()
     self.network = utils.import_object(FLAGS.network_manager)
     self.stubs = stubout.StubOutForTesting()
     self.flags(xenapi_connection_url='test_url',
                xenapi_connection_password='******',
                instance_name_template='%d')
     xenapi_fake.reset()
     xenapi_fake.create_local_srs()
     xenapi_fake.create_local_pifs()
     db_fakes.stub_out_db_instance_api(self.stubs)
     xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
     stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
     stubs.stubout_get_this_vm_uuid(self.stubs)
     stubs.stubout_stream_disk(self.stubs)
     stubs.stubout_is_vdi_pv(self.stubs)
     self.stubs.Set(vmops.VMOps, '_configure_instance',
             configure_instance)
     self.stubs.Set(vmops.VMOps, '_find_rescue_vbd_ref',
             _find_rescue_vbd_ref)
     stubs.stub_out_vm_methods(self.stubs)
     tank_stubs.stubout_tank_client(self.stubs)
     fake_utils.stub_out_utils_execute(self.stubs)
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = context.RequestContext(self.user_id, self.project_id)
     self.conn = xenapi_conn.get_connection(False)
Ejemplo n.º 8
0
    def setUp(self):
        self.maxDiff = None
        super(ServerActionsControllerTest, self).setUp()

        self.stubs = stubout.StubOutForTesting()
        fakes.stub_out_auth(self.stubs)
        self.stubs.Set(engine.db, 'instance_get', return_server_by_id)
        self.stubs.Set(engine.db, 'instance_get_by_uuid', return_server_by_uuid)
        self.stubs.Set(engine.db, 'instance_update', instance_update)

        fakes.stub_out_tank(self.stubs)
        fakes.stub_out_nw_api(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        self.snapshot = fakes.stub_out_compute_api_snapshot(self.stubs)
        service_class = 'engine.image.tank.TankImageService'
        self.service = utils.import_object(service_class)
        self.context = context.RequestContext(1, None)
        self.service.delete_all()
        self.sent_to_tank = {}
        fakes.stub_out_tank_add_image(self.stubs, self.sent_to_tank)
        self.flags(allow_instance_snapshots=True)
        self.uuid = FAKE_UUID
        self.url = '/v2/fake/servers/%s/action' % self.uuid

        self.controller = servers.Controller()
Ejemplo n.º 9
0
 def __init__(self, scheduler_driver=None, *args, **kwargs):
     self.zone_manager = zone_manager.ZoneManager()
     if not scheduler_driver:
         scheduler_driver = FLAGS.scheduler_driver
     self.driver = utils.import_object(scheduler_driver)
     self.driver.set_zone_manager(self.zone_manager)
     super(SchedulerManager, self).__init__(*args, **kwargs)
Ejemplo n.º 10
0
 def setUp(self):
     super(ConsoleTestCase, self).setUp()
     self.flags(console_driver='engine.console.fake.FakeConsoleProxy',
                stub_compute=True)
     self.console = utils.import_object(FLAGS.console_manager)
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = context.RequestContext(self.user_id, self.project_id)
     self.host = 'test_compute_host'
Ejemplo n.º 11
0
def _get_drivers():
    """Instantiates and returns drivers based on the flag values."""
    global drivers
    if not drivers:
        drivers = []
        for notification_driver in FLAGS.list_notifier_drivers:
            try:
                drivers.append(utils.import_object(notification_driver))
            except ClassNotFound as e:
                drivers.append(ImportFailureNotifier(e))
    return drivers
Ejemplo n.º 12
0
 def __init__(self, volume_driver=None, *args, **kwargs):
     """Load the driver from the one specified in args, or from flags."""
     if not volume_driver:
         volume_driver = FLAGS.volume_driver
     self.driver = utils.import_object(volume_driver)
     super(VolumeManager, self).__init__(service_name='volume',
                                                 *args, **kwargs)
     # NOTE(vish): Implementation specific db handling is done
     #             by the driver.
     self.driver.db = self.db
     self._last_volume_stats = []
Ejemplo n.º 13
0
    def setUp(self):
        super(VMWareAPIVMTestCase, self).setUp()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(vmwareapi_host_ip='test_url',
                   vmwareapi_host_username='******',
                   vmwareapi_host_password='******')
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        self.network = utils.import_object(FLAGS.network_manager)
        vmwareapi_fake.reset()
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.set_stubs(self.stubs)
        tank_stubs.stubout_tank_client(self.stubs)
        self.conn = vmwareapi_conn.get_connection(False)
        # NOTE(vish): none of the network plugging code is actually
        #             being tested
        self.network_info = [({
            'bridge': 'fa0',
            'id': 0,
            'vlan': None,
            'bridge_interface': None,
            'injected': True
        }, {
            'broadcast':
            '192.168.0.255',
            'dns': ['192.168.0.1'],
            'gateway':
            '192.168.0.1',
            'gateway_v6':
            'dead:beef::1',
            'ip6s': [{
                'enabled': '1',
                'ip': 'dead:beef::dcad:beff:feef:0',
                'netmask': '64'
            }],
            'ips': [{
                'enabled': '1',
                'ip': '192.168.0.100',
                'netmask': '255.255.255.0'
            }],
            'label':
            'fake',
            'mac':
            'DE:AD:BE:EF:00:00',
            'rxtx_cap':
            3
        })]

        self.image = {
            'id': 'c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c',
            'disk_format': 'vhd',
            'size': 512,
        }
Ejemplo n.º 14
0
def _get_drivers():
    """Instantiates and returns drivers based on the flag values."""
    global drivers
    if not drivers:
        drivers = []
        for notification_driver in FLAGS.list_notifier_drivers:
            try:
                drivers.append(utils.import_object(notification_driver))
            except ClassNotFound as e:
                drivers.append(ImportFailureNotifier(e))
    return drivers
Ejemplo n.º 15
0
    def __init__(self, driver=None, *args, **kwargs):
        """Inits the driver from parameter or flag

        __init__ is run every time AuthManager() is called, so we only
        reset the driver if it is not set or a new driver is specified.
        """
        self.network_manager = utils.import_object(FLAGS.network_manager)
        if driver or not getattr(self, 'driver', None):
            self.driver = utils.import_class(driver or FLAGS.auth_driver)
        if AuthManager.mc is None:
            AuthManager.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
Ejemplo n.º 16
0
 def __init__(self, volume_driver=None, *args, **kwargs):
     """Load the driver from the one specified in args, or from flags."""
     if not volume_driver:
         volume_driver = FLAGS.volume_driver
     self.driver = utils.import_object(volume_driver)
     super(VolumeManager, self).__init__(service_name='volume',
                                         *args,
                                         **kwargs)
     # NOTE(vish): Implementation specific db handling is done
     #             by the driver.
     self.driver.db = self.db
     self._last_volume_stats = []
Ejemplo n.º 17
0
def notify(publisher_id, event_type, priority, payload):
    """
    Sends a notification using the specified driver

    Notify parameters:

    publisher_id - the source worker_type.host of the message
    event_type - the literal type of event (ex. Instance Creation)
    priority - patterned after the enumeration of Python logging levels in
               the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
    payload - A python dictionary of attributes

    Outgoing message format includes the above parameters, and appends the
    following:

    message_id - a UUID representing the id for this notification
    timestamp - the GMT timestamp the notification was sent at

    The composite message will be constructed as a dictionary of the above
    attributes, which will then be sent via the transport mechanism defined
    by the driver.

    Message example:

    {'message_id': str(uuid.uuid4()),
     'publisher_id': 'compute.host1',
     'timestamp': utils.utcnow(),
     'priority': 'WARN',
     'event_type': 'compute.create_instance',
     'payload': {'instance_id': 12, ... }}

    """
    if priority not in log_levels:
        raise BadPriorityException(
                 _('%s not in valid priorities' % priority))

    # Ensure everything is JSON serializable.
    payload = utils.to_primitive(payload, convert_instances=True)

    driver = utils.import_object(FLAGS.notification_driver)
    msg = dict(message_id=str(uuid.uuid4()),
                   publisher_id=publisher_id,
                   event_type=event_type,
                   priority=priority,
                   payload=payload,
                   timestamp=str(utils.utcnow()))
    try:
        driver.notify(msg)
    except Exception, e:
        LOG.exception(_("Problem '%(e)s' attempting to "
                        "send to notification system. Payload=%(payload)s" %
                        locals()))
Ejemplo n.º 18
0
def notify(publisher_id, event_type, priority, payload):
    """
    Sends a notification using the specified driver

    Notify parameters:

    publisher_id - the source worker_type.host of the message
    event_type - the literal type of event (ex. Instance Creation)
    priority - patterned after the enumeration of Python logging levels in
               the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
    payload - A python dictionary of attributes

    Outgoing message format includes the above parameters, and appends the
    following:

    message_id - a UUID representing the id for this notification
    timestamp - the GMT timestamp the notification was sent at

    The composite message will be constructed as a dictionary of the above
    attributes, which will then be sent via the transport mechanism defined
    by the driver.

    Message example:

    {'message_id': str(uuid.uuid4()),
     'publisher_id': 'compute.host1',
     'timestamp': utils.utcnow(),
     'priority': 'WARN',
     'event_type': 'compute.create_instance',
     'payload': {'instance_id': 12, ... }}

    """
    if priority not in log_levels:
        raise BadPriorityException(_('%s not in valid priorities' % priority))

    # Ensure everything is JSON serializable.
    payload = utils.to_primitive(payload, convert_instances=True)

    driver = utils.import_object(FLAGS.notification_driver)
    msg = dict(message_id=str(uuid.uuid4()),
               publisher_id=publisher_id,
               event_type=event_type,
               priority=priority,
               payload=payload,
               timestamp=str(utils.utcnow()))
    try:
        driver.notify(msg)
    except Exception, e:
        LOG.exception(
            _("Problem '%(e)s' attempting to "
              "send to notification system. Payload=%(payload)s" % locals()))
Ejemplo n.º 19
0
    def setUp(self):
        super(UsageInfoTestCase, self).setUp()
        self.flags(connection_type='fake',
                   stub_network=True,
                   notification_driver='engine.notifier.test_notifier',
                   network_manager='engine.network.manager.FlatManager')
        self.compute = utils.import_object(FLAGS.compute_manager)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        test_notifier.NOTIFICATIONS = []

        def fake_show(meh, context, id):
            return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}

        self.stubs.Set(engine.image.fake._FakeImageService, 'show', fake_show)
    def setUp(self):
        super(UsageInfoTestCase, self).setUp()
        self.flags(connection_type='fake',
                   stub_network=True,
                   notification_driver='engine.notifier.test_notifier',
                   network_manager='engine.network.manager.FlatManager')
        self.compute = utils.import_object(FLAGS.compute_manager)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        test_notifier.NOTIFICATIONS = []

        def fake_show(meh, context, id):
            return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}

        self.stubs.Set(engine.image.fake._FakeImageService, 'show', fake_show)
Ejemplo n.º 21
0
    def __init__(self, q_conn=None, ipam_lib=None, *args, **kwargs):
        """Initialize two key libraries, the connection to a
           Quantum service, and the library for implementing IPAM.

           Calls inherited FlatManager constructor.
        """

        if not q_conn:
            q_conn = quantum_connection.QuantumClientConnection()
        self.q_conn = q_conn

        if not ipam_lib:
            ipam_lib = FLAGS.quantum_ipam_lib
        self.ipam = utils.import_object(ipam_lib).get_ipam_lib(self)

        super(QuantumManager, self).__init__(*args, **kwargs)
Ejemplo n.º 22
0
    def setUp(self):
        super(DriverTestCase, self).setUp()
        self.flags(volume_driver=self.driver_name,
                   logging_default_format_string="%(message)s")
        self.volume = utils.import_object(FLAGS.volume_manager)
        self.context = context.get_admin_context()
        self.output = ""

        def _fake_execute(_command, *_args, **_kwargs):
            """Fake _execute."""
            return self.output, None
        self.volume.driver.set_execute(_fake_execute)

        log = logging.getLogger()
        self.stream = cStringIO.StringIO()
        log.addHandler(logging.StreamHandler(self.stream))

        inst = {}
        self.instance_id = db.instance_create(self.context, inst)['id']
Ejemplo n.º 23
0
    def setUp(self):
        super(DriverTestCase, self).setUp()
        self.flags(volume_driver=self.driver_name,
                   logging_default_format_string="%(message)s")
        self.volume = utils.import_object(FLAGS.volume_manager)
        self.context = context.get_admin_context()
        self.output = ""

        def _fake_execute(_command, *_args, **_kwargs):
            """Fake _execute."""
            return self.output, None

        self.volume.driver.set_execute(_fake_execute)

        log = logging.getLogger()
        self.stream = cStringIO.StringIO()
        log.addHandler(logging.StreamHandler(self.stream))

        inst = {}
        self.instance_id = db.instance_create(self.context, inst)['id']
Ejemplo n.º 24
0
    def setUp(self):
        super(VMWareAPIVMTestCase, self).setUp()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(vmwareapi_host_ip='test_url',
                   vmwareapi_host_username='******',
                   vmwareapi_host_password='******')
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        self.network = utils.import_object(FLAGS.network_manager)
        vmwareapi_fake.reset()
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.set_stubs(self.stubs)
        tank_stubs.stubout_tank_client(self.stubs)
        self.conn = vmwareapi_conn.get_connection(False)
        # NOTE(vish): none of the network plugging code is actually
        #             being tested
        self.network_info = [({'bridge': 'fa0',
                               'id': 0,
                               'vlan': None,
                               'bridge_interface': None,
                               'injected': True},
                          {'broadcast': '192.168.0.255',
                           'dns': ['192.168.0.1'],
                           'gateway': '192.168.0.1',
                           'gateway_v6': 'dead:beef::1',
                           'ip6s': [{'enabled': '1',
                                     'ip': 'dead:beef::dcad:beff:feef:0',
                                           'netmask': '64'}],
                           'ips': [{'enabled': '1',
                                    'ip': '192.168.0.100',
                                    'netmask': '255.255.255.0'}],
                           'label': 'fake',
                           'mac': 'DE:AD:BE:EF:00:00',
                           'rxtx_cap': 3})]

        self.image = {
            'id': 'c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c',
            'disk_format': 'vhd',
            'size': 512,
        }
Ejemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     super(MetadataManager, self).__init__(*args, **kwargs)
     self.network_driver = utils.import_object(FLAGS.network_driver)
Ejemplo n.º 26
0
 def setUp(self):
     super(LinuxNetworkTestCase, self).setUp()
     network_driver = FLAGS.network_driver
     self.driver = utils.import_object(network_driver)
     self.driver.db = db
Ejemplo n.º 27
0
 def __init__(self, db_driver=None):
     if not db_driver:
         db_driver = FLAGS.db_driver
     self.db = utils.import_object(db_driver)  # pylint: disable=C0103
Ejemplo n.º 28
0
 def __init__(self, application, db_driver=None):
     if not db_driver:
         db_driver = FLAGS.db_driver
     self.db = utils.import_object(db_driver)
     self.auth = auth.manager.AuthManager()
     super(KeystoneAuthShim, self).__init__(application)
Ejemplo n.º 29
0
 def __init__(self, console_driver=None, *args, **kwargs):
     if not console_driver:
         console_driver = FLAGS.console_driver
     self.driver = utils.import_object(console_driver)
     super(ConsoleProxyManager, self).__init__(*args, **kwargs)
     self.driver.host = self.host
Ejemplo n.º 30
0
    def __init__(self):
        super(MultiScheduler, self).__init__()
        compute_driver = utils.import_object(FLAGS.compute_scheduler_driver)
        volume_driver = utils.import_object(FLAGS.volume_scheduler_driver)

        self.drivers = {'compute': compute_driver, 'volume': volume_driver}
Ejemplo n.º 31
0
def _get_impl():
    """Delay import of rpc_backend until FLAGS are loaded."""
    global _RPCIMPL
    if _RPCIMPL is None:
        _RPCIMPL = import_object(FLAGS.rpc_backend)
    return _RPCIMPL
Ejemplo n.º 32
0
 def __init__(self, *args, **kwargs):
     super(MetadataManager, self).__init__(*args, **kwargs)
     self.network_driver = utils.import_object(FLAGS.network_driver)
Ejemplo n.º 33
0
 def __init__(self, session):
     """Initializer."""
     self._session = session
     self._vif_driver = utils.import_object(FLAGS.vmware_vif_driver)
Ejemplo n.º 34
0
 def setUp(self):
     super(LinuxNetworkTestCase, self).setUp()
     network_driver = FLAGS.network_driver
     self.driver = utils.import_object(network_driver)
     self.driver.db = db
Ejemplo n.º 35
0
 def __init__(self, session):
     """Initializer."""
     self._session = session
     self._vif_driver = utils.import_object(FLAGS.vmware_vif_driver)
Ejemplo n.º 36
0
 def __init__(self, application, db_driver=None):
     if not db_driver:
         db_driver = FLAGS.db_driver
     self.db = utils.import_object(db_driver)
     self.auth = auth.manager.AuthManager()
     super(AuthMiddleware, self).__init__(application)
Ejemplo n.º 37
0
 def __init__(self, console_driver=None, *args, **kwargs):
     if not console_driver:
         console_driver = FLAGS.console_driver
     self.driver = utils.import_object(console_driver)
     super(ConsoleProxyManager, self).__init__(*args, **kwargs)
     self.driver.host = self.host
Ejemplo n.º 38
0
 def __init__(self, console_driver=None, *args, **kwargs):
     self.driver = utils.import_object(FLAGS.console_driver)
     super(ConsoleVMRCManager, self).__init__(*args, **kwargs)
Ejemplo n.º 39
0
            if not gateway:
                # If we weren't instructed to act as a gateway then add the
                # appropriate flows to block all non-dhcp traffic.
                _execute('ovs-ofctl',
                    'add-flow', bridge, "priority=1,actions=drop")
                _execute('ovs-ofctl', 'add-flow', bridge,
                    "udp,tp_dst=67,dl_dst=%s,priority=2,actions=normal" %
                    mac_address)
                # .. and make sure iptbles won't forward it as well.
                iptables_manager.ipv4['filter'].add_rule('FORWARD',
                        '--in-interface %s -j DROP' % bridge)
                iptables_manager.ipv4['filter'].add_rule('FORWARD',
                        '--out-interface %s -j DROP' % bridge)
            else:
                iptables_manager.ipv4['filter'].add_rule('FORWARD',
                        '--in-interface %s -j ACCEPT' % bridge)
                iptables_manager.ipv4['filter'].add_rule('FORWARD',
                        '--out-interface %s -j ACCEPT' % bridge)

        return dev

    def unplug(self, network):
        return self.get_dev(network)

    def get_dev(self, network):
        dev = "gw-" + str(network['uuid'][0:11])
        return dev

iptables_manager = IptablesManager()
interface_driver = utils.import_object(FLAGS.linuxnet_interface_driver)