def setUp(self):
        super(IPMINativeDriverTestCase, self).setUp()
        self.dbapi = db_api.get_instance()
        self.driver = mgr_utils.get_mocked_node_manager(
                      driver='fake_ipminative')

        n = db_utils.get_test_node(
                driver='fake_ipminative',
                driver_info=db_utils.ipmi_info)
        self.dbapi = db_api.get_instance()
        self.node = self.dbapi.create_node(n)
        self.info = ipminative._parse_driver_info(self.node)
Exemplo n.º 2
0
    def setUp(self):
        super(SSHDriverTestCase, self).setUp()
        self.context = context.get_admin_context()
        mgr_utils.mock_the_extension_manager(driver="fake_ssh")
        self.driver = driver_factory.get_driver("fake_ssh")
        n = db_utils.get_test_node(
                driver='fake_ssh',
                driver_info=INFO_DICT)
        self.dbapi = dbapi.get_instance()
        self.node = self.dbapi.create_node(n)
        self.port = self.dbapi.create_port(db_utils.get_test_port(
                                                         node_id=self.node.id))
        self.sshclient = paramiko.SSHClient()

        #setup these mocks because most tests use them
        self.parse_drv_info_patcher = mock.patch.object(ssh,
                                                        '_parse_driver_info')
        self.parse_drv_info_mock = None
        self.get_mac_addr_patcher = mock.patch.object(
                ssh,
                '_get_nodes_mac_addresses')
        self.get_mac_addr_mock = self.get_mac_addr_patcher.start()
        self.get_conn_patcher = mock.patch.object(ssh, '_get_connection')
        self.get_conn_mock = self.get_conn_patcher.start()

        def stop_patchers():
            if self.parse_drv_info_mock:
                self.parse_drv_info_patcher.stop()
            if self.get_mac_addr_mock:
                self.get_mac_addr_patcher.stop()
            if self.get_conn_mock:
                self.get_conn_patcher.stop()

        self.addCleanup(stop_patchers)
Exemplo n.º 3
0
    def setUp(self):
        super(TestACL, self).setUp()

        self.environ = {"fake.cache": utils.FakeMemcache()}
        self.fake_db_node = db_utils.get_test_node(chassis_id=None)
        self.dbapi = db_api.get_instance()
        self.node_path = "/nodes/%s" % self.fake_db_node["uuid"]
Exemplo n.º 4
0
 def setUp(self):
     super(FakeDriverTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.dbapi = db_api.get_instance()
     self.driver = mgr_utils.get_mocked_node_manager(driver='fake')
     self.node = db_utils.get_test_node()
     self.dbapi.create_node(self.node)
Exemplo n.º 5
0
 def setUp(self):
     super(IPMINativePrivateMethodTestCase, self).setUp()
     self.node = obj_utils.create_test_node(self.context,
                                            driver='fake_ipminative',
                                            driver_info=INFO_DICT)
     self.dbapi = db_api.get_instance()
     self.info = ipminative._parse_driver_info(self.node)
 def setUp(self):
     super(IloPXEVendorPassthruTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     mgr_utils.mock_the_extension_manager(driver="pxe_ilo")
     self.node = obj_utils.create_test_node(self.context,
             driver='pxe_ilo', driver_info=INFO_DICT)
 def setUp(self):
     super(IloVirtualMediaAgentDeployTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     mgr_utils.mock_the_extension_manager(driver="agent_ilo")
     self.node = obj_utils.create_test_node(self.context,
             driver='agent_ilo', driver_info=INFO_DICT)
Exemplo n.º 8
0
 def setUp(self):
     super(ManagerTestCase, self).setUp()
     self.service = manager.ConductorManager('test-host', 'test-topic')
     self.context = context.get_admin_context()
     self.dbapi = dbapi.get_instance()
     mgr_utils.mock_the_extension_manager()
     self.driver = driver_factory.get_driver("fake")
Exemplo n.º 9
0
 def setUp(self):
     super(PXEPrivateMethodsTestCase, self).setUp()
     n = {"driver": "fake_pxe", "driver_info": INFO_DICT}
     mgr_utils.mock_the_extension_manager(driver="fake_pxe")
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     self.node = obj_utils.create_test_node(self.context, **n)
Exemplo n.º 10
0
 def setUp(self):
     super(FunctionalTest, self).setUp()
     cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
     cfg.CONF.set_override("policy_file",
                           self.path_get('tests/policy.json'))
     self.app = self._make_app()
     self.dbapi = dbapi.get_instance()
Exemplo n.º 11
0
    def init_host(self):
        self.dbapi = dbapi.get_instance()

        self.driver_factory = driver_factory.DriverFactory()
        self.drivers = self.driver_factory.names
        """List of driver names which this conductor supports."""

        try:
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})
        except exception.ConductorAlreadyRegistered:
            LOG.warn(_("A conductor with hostname %(hostname)s "
                       "was previously registered. Updating registration")
                       % {'hostname': self.host})
            self.dbapi.unregister_conductor(self.host)
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})

        self.ring_manager = hash.HashRingManager()
        """Consistent hash ring which maps drivers to conductors."""

        self._worker_pool = greenpool.GreenPool(
                                size=CONF.conductor.workers_pool_size)
        """GreenPool of background workers for performing tasks async."""

        # Spawn a dedicated greenthread for the keepalive
        try:
            self._keepalive_evt = threading.Event()
            self._spawn_worker(self._conductor_service_record_keepalive)
        except exception.NoFreeConductorWorker:
            with excutils.save_and_reraise_exception():
                LOG.critical(_('Failed to start keepalive'))
                self.del_host()
 def setUp(self):
     super(TestPXEUtils, self).setUp()
     mgr_utils.mock_the_extension_manager(driver="fake")
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     self.pxe_options = {
         'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
         'ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                     u'ramdisk',
         'iscsi_target_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
                             u'c123',
         'deployment_ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
                                u'f33c123/deploy_ramdisk',
         'pxe_append_params': 'test_param',
         'aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                     u'kernel',
         'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
         'ironic_api_url': 'http://192.168.122.184:6385',
         'deployment_aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
                                u'c02d7f33c123/deploy_kernel',
         'disk': 'cciss/c0d0,sda,hda,vda'
     }
     self.agent_pxe_options = {
         'deployment_ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
                                u'f33c123/deploy_ramdisk',
         'pxe_append_params': 'test_param',
         'aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
                     u'kernel',
         'ipa-api-url': 'http://192.168.122.184:6385',
         'deployment_aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
                                u'c02d7f33c123/deploy_kernel',
     }
     self.node = object_utils.create_test_node(self.context)
Exemplo n.º 13
0
    def start(self):
        super(ConductorManager, self).start()
        self.dbapi = dbapi.get_instance()

        # create a DriverFactory instance, which initializes the stevedore
        # extension manager, when the service starts.
        # TODO(deva): Enable re-loading of the DriverFactory to load new
        #             extensions without restarting the whole service.
        df = driver_factory.DriverFactory()
        self.drivers = df.names
        """List of driver names which this conductor supports."""

        try:
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})
        except exception.ConductorAlreadyRegistered:
            LOG.warn(_("A conductor with hostname %(hostname)s "
                       "was previously registered. Updating registration")
                       % {'hostname': self.host})
            self.dbapi.unregister_conductor(self.host)
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})

        self.driver_rings = self._get_current_driver_rings()
        """Consistent hash ring which maps drivers to conductors."""

        self._worker_pool = greenpool.GreenPool(size=CONF.rpc_thread_pool_size)
        """GreenPool of background workers for performing tasks async."""
Exemplo n.º 14
0
 def setUp(self):
     super(ManagerRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.dbapi = dbapi.get_instance()
     self.fake_node = json.to_primitive(dbutils.get_test_node(
                                         control_driver='fake',
                                         deploy_driver='fake'))
Exemplo n.º 15
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
     self.fake_node = dbutils.get_test_node(driver='fake-driver')
     self.fake_node_obj = objects.Node._from_db_object(
                                                 objects.Node(self.context),
                                                 self.fake_node)
Exemplo n.º 16
0
 def setUp(self):
     super(UtilsTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.dbapi = db_api.get_instance()
     mgr_utils.mock_the_extension_manager()
     self.driver = driver_factory.get_driver("fake")
     self.node = obj_utils.create_test_node(self.context)
Exemplo n.º 17
0
    def start(self):
        super(ConductorManager, self).start()
        self.dbapi = dbapi.get_instance()

        df = driver_factory.DriverFactory()

        self.drivers = df.names
        """List of driver names which this conductor supports."""

        try:
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})
        except exception.ConductorAlreadyRegistered:
            LOG.warn(_("A conductor with hostname %(hostname)s "
                       "was previously registered. Updating registration")
                       % {'hostname': self.host})
            self.dbapi.unregister_conductor(self.host)
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})

        self.ring_manager = hash.HashRingManager()
        """Consistent hash ring which maps drivers to conductors."""

        self._worker_pool = greenpool.GreenPool(size=CONF.rpc_thread_pool_size)
        """GreenPool of background workers for performing tasks async."""
Exemplo n.º 18
0
    def setUp(self):
        super(TaskManagerTestCase, self).setUp()
        self.dbapi = dbapi.get_instance()
        self.driver = mgr_utils.get_mocked_node_manager()

        self.uuids = [create_fake_node(i) for i in xrange(1, 6)]
        self.uuids.sort()
Exemplo n.º 19
0
 def setUp(self):
     super(BackfillVersionTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.dbapi = db_api.get_instance()
     obj_mapping = release_mappings.RELEASE_MAPPING['ocata']['objects']
     self.node_ver = obj_mapping['Node'][0]
     self.chassis_ver = obj_mapping['Chassis'][0]
Exemplo n.º 20
0
 def setUp(self):
     super(SSHDriverTestCase, self).setUp()
     self.driver = mgr_utils.get_mocked_node_manager(driver="fake_ssh")
     self.node = db_utils.get_test_node(driver="fake_ssh", driver_info=db_utils.ssh_info)
     self.dbapi = dbapi.get_instance()
     self.dbapi.create_node(self.node)
     self.sshclient = paramiko.SSHClient()
Exemplo n.º 21
0
    def setUp(self):
        super(TestACL, self).setUp()

        self.environ = {'fake.cache': utils.FakeMemcache()}
        self.fake_node = db_utils.get_test_node(chassis_id=None)
        self.dbapi = db_api.get_instance()
        self.node_path = '/nodes/%s' % self.fake_node['uuid']
Exemplo n.º 22
0
    def setUp(self):
        super(SSHDriverTestCase, self).setUp()
        self.driver = mgr_utils.get_mocked_node_manager(driver='fake_ssh')
        self.node = db_utils.get_test_node(
                        driver='fake_ssh',
                        driver_info=INFO_DICT)
        self.dbapi = dbapi.get_instance()
        self.dbapi.create_node(self.node)
        self.sshclient = paramiko.SSHClient()

        #setup these mocks because most tests use them
        self.parse_drv_info_patcher = mock.patch.object(ssh,
                                                        '_parse_driver_info')
        self.parse_drv_info_mock = None
        self.get_mac_addr_patcher = mock.patch.object(
                ssh,
                '_get_nodes_mac_addresses')
        self.get_mac_addr_mock = self.get_mac_addr_patcher.start()
        self.get_conn_patcher = mock.patch.object(ssh, '_get_connection')
        self.get_conn_mock = self.get_conn_patcher.start()

        def stop_patchers():
            if self.parse_drv_info_mock:
                self.parse_drv_info_patcher.stop()
            if self.get_mac_addr_mock:
                self.get_mac_addr_patcher.stop()
            if self.get_conn_mock:
                self.get_conn_patcher.stop()

        self.addCleanup(stop_patchers)
Exemplo n.º 23
0
 def setUp(self):
     super(IloCommonMethodsTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     mgr_utils.mock_the_extension_manager(driver="fake_ilo")
     self.node = obj_utils.create_test_node(self.context,
             driver='fake_ilo', driver_info=INFO_DICT)
Exemplo n.º 24
0
 def setUp(self):
     super(TaskManagerSetup, self).setUp()
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     mgr_utils.mock_the_extension_manager()
     self.driver = driver_factory.get_driver("fake")
     self.config(host='test-host')
Exemplo n.º 25
0
    def setUp(self):
        # This method creates a port for every test and
        # replaces a test for creating a port.
        super(DbPortTestCase, self).setUp()
        self.dbapi = dbapi.get_instance()

        self.n = utils.get_test_node()
        self.p = utils.get_test_port()
Exemplo n.º 26
0
 def setUp(self):
     super(DracPowerInternalMethodsTestCase, self).setUp()
     driver_info = INFO_DICT
     db_node = db_utils.get_test_node(driver='fake_drac',
                                      driver_info=driver_info,
                                      instance_uuid='instance_uuid_123')
     self.dbapi = dbapi.get_instance()
     self.node = self.dbapi.create_node(db_node)
Exemplo n.º 27
0
 def setUp(self):
     super(PXEPrivateMethodsTestCase, self).setUp()
     n = {
           'driver': 'fake_pxe',
           'driver_info': INFO_DICT,
           'instance_uuid': 'instance_uuid_123'}
     self.dbapi = dbapi.get_instance()
     self.node = self._create_test_node(**n)
Exemplo n.º 28
0
def create_fake_node(i):
    dbh = dbapi.get_instance()
    node = utils.get_test_node(id=i,
                               uuid=uuidutils.generate_uuid(),
                               control_driver='fake',
                               deploy_driver='fake')
    dbh.create_node(node)
    return node['uuid']
Exemplo n.º 29
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.dbapi = dbapi.get_instance()
     self.fake_node = json.to_primitive(dbutils.get_test_node())
     self.fake_node_obj = objects.Node._from_db_object(
                                                 objects.Node(),
                                                 self.fake_node)
Exemplo n.º 30
0
    def setUp(self):
        super(SNMPDriverTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.dbapi = db_api.get_instance()
        mgr_utils.mock_the_extension_manager(driver='fake_snmp')

        self.node = obj_utils.create_test_node(self.context,
                                               driver='fake_snmp',
                                               driver_info=INFO_DICT)
Exemplo n.º 31
0
def create_test_conductor(**kw):
    """Create test conductor entry in DB and return Conductor DB object.

    Function to be used to create test Conductor objects in the database.

    :param kw: kwargs with overriding values for conductor's attributes.
    :returns: Test Conductor DB object.

    """
    conductor = get_test_conductor(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del conductor['id']
    dbapi = db_api.get_instance()
    return dbapi.register_conductor(conductor)
Exemplo n.º 32
0
def create_test_bios_setting(**kw):
    """Create test bios entry in DB and return BIOSSetting DB object.

    Function to be used to create test BIOSSetting object in the database.

    :param kw: kwargs with overriding values for node bios settings.
    :returns: Test BIOSSetting DB object.

    """
    bios_setting = get_test_bios_setting(**kw)
    dbapi = db_api.get_instance()
    node_id = bios_setting['node_id']
    version = bios_setting['version']
    settings = [{'name': bios_setting['name'], 'value': bios_setting['value']}]
    return dbapi.create_bios_setting_list(node_id, settings, version)[0]
Exemplo n.º 33
0
def create_test_node(**kw):
    """Create test node entry in DB and return Node DB object.

    Function to be used to create test Node objects in the database.

    :param kw: kwargs with overriding values for node's attributes.
    :returns: Test Node DB object.

    """
    node = get_test_node(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del node['id']
    dbapi = db_api.get_instance()
    return dbapi.create_node(node)
Exemplo n.º 34
0
    def setUp(self):
        super(SeaMicroPowerDriverTestCase, self).setUp()
        if not seamicroclient:
            self.skipTest("Seamicroclient library not found")
        mgr_utils.mock_the_extension_manager(driver='fake_seamicro')
        self.driver = driver_factory.get_driver('fake_seamicro')
        db_node = db_utils.get_test_node(driver='fake_seamicro',
                                         driver_info=INFO_DICT)
        self.dbapi = dbapi.get_instance()
        self.node = self.dbapi.create_node(db_node)
        self.get_server_patcher = mock.patch.object(seamicro, '_get_server')

        self.get_server_mock = None
        self.Server = Fake_Server
        self.Volume = Fake_Volume
Exemplo n.º 35
0
 def setUp(self):
     super(TestNeutron, self).setUp()
     mgr_utils.mock_the_extension_manager(driver='fake')
     self.config(enabled_drivers=['fake'])
     self.config(url='test-url', url_timeout=30, group='neutron')
     self.config(insecure=False,
                 certfile='test-file',
                 admin_user='******',
                 admin_tenant_name='test-admin-tenant',
                 admin_password='******',
                 auth_uri='test-auth-uri',
                 group='keystone_authtoken')
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     self.node = object_utils.create_test_node(self.context)
Exemplo n.º 36
0
def create_test_volume_target(**kw):
    """Create test target entry in DB and return VolumeTarget DB object.

    Function to be used to create test VolumeTarget objects in the database.

    :param kw: kwargs with overriding values for target's attributes.
    :returns: Test VolumeTarget DB object.

    """
    target = get_test_volume_target(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del target['id']
    dbapi = db_api.get_instance()
    return dbapi.create_volume_target(target)
Exemplo n.º 37
0
def create_test_chassis(**kw):
    """Create test chassis entry in DB and return Chassis DB object.

    Function to be used to create test Chassis objects in the database.

    :param kw: kwargs with overriding values for chassis's attributes.
    :returns: Test Chassis DB object.

    """
    chassis = get_test_chassis(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del chassis['id']
    dbapi = db_api.get_instance()
    return dbapi.create_chassis(chassis)
Exemplo n.º 38
0
def create_test_portgroup(**kw):
    """Create test portgroup entry in DB and return Portgroup DB object.

    Function to be used to create test Portgroup objects in the database.

    :param kw: kwargs with overriding values for port's attributes.
    :returns: Test Portgroup DB object.

    """
    portgroup = get_test_portgroup(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del portgroup['id']
    dbapi = db_api.get_instance()
    return dbapi.create_portgroup(portgroup)
Exemplo n.º 39
0
    def setUp(self):
        super(FunctionalTest, self).setUp()
        cfg.CONF.set_override("auth_version",
                              "v2.0",
                              group='keystone_authtoken')
        cfg.CONF.set_override("admin_user",
                              "admin",
                              group='keystone_authtoken')
        self.app = self._make_app()
        self.dbapi = dbapi.get_instance()

        def reset_pecan():
            pecan.set_config({}, overwrite=True)

        self.addCleanup(reset_pecan)
Exemplo n.º 40
0
    def __init__(self, context, node_ids, shared=False, driver_name=None):
        """Create a new TaskManager.

        Acquire a lock atomically on a non-empty set of nodes. The lock
        can be either shared or exclusive. Shared locks may be used for
        read-only or non-disruptive actions only, and must be considerate
        to what other threads may be doing on the nodes at the same time.

        :param context: request context
        :param node_ids: A list of ids or uuids of nodes to lock.
        :param shared: Boolean indicating whether to take a shared or exclusive
                       lock. Default: False.
        :param driver_name: The name of the driver to load, if different
                            from the Node's current driver.
        :raises: DriverNotFound
        :raises: NodeAlreadyLocked

        """

        self.context = context
        self.resources = []
        self.shared = shared
        self.dbapi = dbapi.get_instance()

        # instead of generating an exception, DTRT and convert to a list
        if not isinstance(node_ids, list):
            node_ids = [node_ids]

        locked_node_list = []
        try:
            for id in node_ids:
                if not self.shared:
                    # NOTE(deva): Only lock one node at a time so we can ensure
                    #             that only the right nodes are unlocked.
                    #             However, reserve_nodes takes and returns a
                    #             list. This should be refactored.
                    node = self.dbapi.reserve_nodes(CONF.host, [id])[0]
                    locked_node_list.append(node.id)
                else:
                    node = self.dbapi.get_node(id)
                ports = self.dbapi.get_ports_by_node(id)
                driver = driver_factory.get_driver(driver_name or node.driver)

                self.resources.append(NodeResource(node, ports, driver))
        except Exception:
            with excutils.save_and_reraise_exception():
                if locked_node_list:
                    self.dbapi.release_nodes(CONF.host, locked_node_list)
Exemplo n.º 41
0
 def setUp(self):
     super(PXEDriverTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.context.auth_token = '4562138218392831'
     self.temp_dir = tempfile.mkdtemp()
     self.config(tftp_root=self.temp_dir, group='pxe')
     self.temp_dir = tempfile.mkdtemp()
     self.config(images_path=self.temp_dir, group='pxe')
     mgr_utils.mock_the_extension_manager(driver="fake_pxe")
     driver_info = INFO_DICT
     driver_info['pxe_deploy_key'] = 'fake-56789'
     n = db_utils.get_test_node(driver='fake_pxe', driver_info=driver_info)
     self.dbapi = dbapi.get_instance()
     self.node = self.dbapi.create_node(n)
     self.port = self.dbapi.create_port(
         db_utils.get_test_port(node_id=self.node.id))
Exemplo n.º 42
0
    def setUp(self):
        super(SeaMicroPrivateMethodsTestCase, self).setUp()
        n = {
            'driver': 'fake_seamicro',
            'driver_info': INFO_DICT
        }
        self.dbapi = dbapi.get_instance()
        self.node = self._create_test_node(**n)
        self.Server = Fake_Server
        self.Volume = Fake_Volume
        self.Pool = Fake_Pool
        self.config(action_timeout=0, group='seamicro')
        self.config(max_retry=2, group='seamicro')

        self.patcher = mock.patch('eventlet.greenthread.sleep')
        self.mock_sleep = self.patcher.start()
Exemplo n.º 43
0
def _assess_db_performance():
    start = time.time()
    dbapi = db_api.get_instance()
    print('Phase - Assess DB performance')
    _add_a_line()
    got_connection = time.time()
    nodes = dbapi.get_node_list()
    node_count = len(nodes)
    query_complete = time.time()
    delta = _calculate_delta(start, got_connection)
    print('Obtained DB client in %s seconds.' % delta)
    delta = _calculate_delta(got_connection, query_complete)
    print('Returned %s nodes in python %s seconds from the DB.\n' %
          (node_count, delta))
    # return node count for future use.
    return node_count
Exemplo n.º 44
0
class Conductor(base.IronicObject):

    dbapi = db_api.get_instance()

    fields = {
        'id': int,
        'drivers': utils.list_or_none,
        'hostname': str,
    }

    @staticmethod
    def _from_db_object(conductor, db_obj):
        """Converts a database entity to a formal object."""
        for field in conductor.fields:
            conductor[field] = db_obj[field]

        conductor.obj_reset_changes()
        return conductor

    @base.remotable_classmethod
    def get_by_hostname(cls, context, hostname):
        """Get a Conductor record by its hostname.

        :param hostname: the hostname on which a Conductor is running
        :returns: a :class:`Conductor` object.
        """
        db_obj = cls.dbapi.get_conductor(hostname)
        return Conductor._from_db_object(cls(), db_obj)

    def save(self, context):
        """Save is not supported by Conductor objects."""
        raise NotImplementedError(
            _('Cannot update a conductor record directly.'))

    @base.remotable
    def refresh(self, context):
        current = self.__class__.get_by_hostname(context,
                                                 hostname=self.hostname)
        for field in self.fields:
            if (hasattr(self, base.get_attrname(field))
                    and self[field] != current[field]):
                self[field] = current[field]

    @base.remotable
    def touch(self, context):
        """Touch this conductor's DB record, marking it as up-to-date."""
        self.dbapi.touch_conductor(self.hostname)
Exemplo n.º 45
0
    def __init__(self, id, t):
        if not NodeManager._driver_factory:
            NodeManager._init_driver_factory()

        self.id = id
        self.task_refs = [t]

        db = dbapi.get_instance()
        self.node = db.get_node(id)
        self.ports = db.get_ports_by_node(id)

        driver_name = self.node.get('driver')
        try:
            self.driver = NodeManager._driver_factory[driver_name].obj
        except KeyError:
            raise exception.IronicException(
                _("Failed to load driver %s.") % driver_name)
Exemplo n.º 46
0
 def setUp(self):
     super(PXEDriverTestCase, self).setUp()
     self.context.auth_token = '4562138218392831'
     self.temp_dir = tempfile.mkdtemp()
     self.config(tftp_root=self.temp_dir, group='pxe')
     self.temp_dir = tempfile.mkdtemp()
     self.config(images_path=self.temp_dir, group='pxe')
     mgr_utils.mock_the_extension_manager(driver="fake_pxe")
     instance_info = INST_INFO_DICT
     instance_info['deploy_key'] = 'fake-56789'
     self.node = obj_utils.create_test_node(self.context,
                                            driver='fake_pxe',
                                            instance_info=instance_info,
                                            driver_info=DRV_INFO_DICT)
     self.dbapi = dbapi.get_instance()
     self.port = obj_utils.create_test_port(self.context,
                                            node_id=self.node.id)
     self.config(group='conductor', api_url='http://127.0.0.1:1234/')
Exemplo n.º 47
0
def create_test_node(**kw):
    """Create test node entry in DB and return Node DB object.

    Function to be used to create test Node objects in the database.

    :param kw: kwargs with overriding values for node's attributes.
    :returns: Test Node DB object.

    """
    node = get_test_node(**kw)
    # Let DB generate an ID if one isn't specified explicitly.
    # Creating a node with tags or traits will raise an exception. If tags or
    # traits are not specified explicitly just delete them.
    for field in {'id', 'tags', 'traits'}:
        if field not in kw:
            del node[field]
    dbapi = db_api.get_instance()
    return dbapi.create_node(node)
Exemplo n.º 48
0
def create_test_deploy_template(**kw):
    """Create a deployment template in the DB and return DeployTemplate model.

    :param kw: kwargs with overriding values for the deploy template.
    :returns: Test DeployTemplate DB object.
    """
    template = get_test_deploy_template(**kw)
    dbapi = db_api.get_instance()
    # Let DB generate an ID if one isn't specified explicitly.
    if 'id' not in kw:
        del template['id']
    if 'steps' not in kw:
        for step in template['steps']:
            del step['id']
            del step['deploy_template_id']
    else:
        for kw_step, template_step in zip(kw['steps'], template['steps']):
            if 'id' not in kw_step:
                del template_step['id']
    return dbapi.create_deploy_template(template)
Exemplo n.º 49
0
    def setUp(self):
        super(UpdateToLatestVersionsTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.dbapi = db_api.get_instance()

        obj_versions = release_mappings.get_object_versions(
            objects=['Node', 'Chassis'])
        master_objs = release_mappings.RELEASE_MAPPING['master']['objects']
        self.node_ver = master_objs['Node'][0]
        self.chassis_ver = master_objs['Chassis'][0]
        self.node_old_ver = self._get_old_object_version(
            self.node_ver, obj_versions['Node'])
        self.chassis_old_ver = self._get_old_object_version(
            self.chassis_ver, obj_versions['Chassis'])
        self.node_version_same = self.node_old_ver == self.node_ver
        self.chassis_version_same = self.chassis_old_ver == self.chassis_ver
        # number of objects with different versions
        self.num_diff_objs = 2
        if self.node_version_same:
            self.num_diff_objs -= 1
        if self.chassis_version_same:
            self.num_diff_objs -= 1
Exemplo n.º 50
0
    def __init__(self, context, node_id, shared=False, driver_name=None):
        """Create a new TaskManager.

        Acquire a lock on a node. The lock can be either shared or
        exclusive. Shared locks may be used for read-only or
        non-disruptive actions only, and must be considerate to what
        other threads may be doing on the same node at the same time.

        :param context: request context
        :param node_id: ID or UUID of node to lock.
        :param shared: Boolean indicating whether to take a shared or exclusive
                       lock. Default: False.
        :param driver_name: The name of the driver to load, if different
                            from the Node's current driver.
        :raises: DriverNotFound
        :raises: NodeNotFound
        :raises: NodeLocked

        """

        self._dbapi = dbapi.get_instance()
        self._spawn_method = None

        self.context = context
        self.node = None
        self.shared = shared

        try:
            if not self.shared:
                self.node = self._dbapi.reserve_node(CONF.host, node_id)
            else:
                self.node = objects.Node.get(context, node_id)
            self.ports = self._dbapi.get_ports_by_node_id(self.node.id)
            self.driver = driver_factory.get_driver(driver_name or
                                                    self.node.driver)
        except Exception:
            with excutils.save_and_reraise_exception():
                self.release_resources()
Exemplo n.º 51
0
 def setUp(self):
     super(TestPXEUtils, self).setUp()
     mgr_utils.mock_the_extension_manager(driver="fake")
     self.dbapi = dbapi.get_instance()
     self.context = context.get_admin_context()
     self.pxe_options = {
         'deployment_key': '0123456789ABCDEFGHIJKLMNOPQRSTUV',
         'ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
         u'ramdisk',
         'iscsi_target_iqn': u'iqn-1be26c0b-03f2-4d2e-ae87-c02d7f33'
         u'c123',
         'deployment_ari_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
         u'f33c123/deploy_ramdisk',
         'pxe_append_params': 'test_param',
         'aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
         u'kernel',
         'deployment_id': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
         'ironic_api_url': 'http://192.168.122.184:6385',
         'deployment_aki_path': u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
         u'c02d7f33c123/deploy_kernel',
         'disk': 'cciss/c0d0,sda,hda,vda'
     }
     self.agent_pxe_options = {
         'deployment_ari_path':
         u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7'
         u'f33c123/deploy_ramdisk',
         'pxe_append_params':
         'test_param',
         'aki_path':
         u'/tftpboot/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/'
         u'kernel',
         'ipa-api-url':
         'http://192.168.122.184:6385',
         'deployment_aki_path':
         u'/tftpboot/1be26c0b-03f2-4d2e-ae87-'
         u'c02d7f33c123/deploy_kernel',
     }
     self.node = object_utils.create_test_node(self.context)
Exemplo n.º 52
0
    def init_host(self):
        self.dbapi = dbapi.get_instance()

        self.driver_factory = driver_factory.DriverFactory()
        self.drivers = self.driver_factory.names
        """List of driver names which this conductor supports."""

        try:
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})
        except exception.ConductorAlreadyRegistered:
            LOG.warn(_("A conductor with hostname %(hostname)s "
                       "was previously registered. Updating registration")
                       % {'hostname': self.host})
            self.dbapi.unregister_conductor(self.host)
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})

        self.ring_manager = hash.HashRingManager()
        """Consistent hash ring which maps drivers to conductors."""

        self._worker_pool = greenpool.GreenPool(
                                size=CONF.conductor.workers_pool_size)
        """GreenPool of background workers for performing tasks async."""

        # Spawn a dedicated greenthread for the keepalive
        try:
            self._keepalive_evt = threading.Event()
            self._spawn_worker(self._conductor_service_record_keepalive)
            LOG.info(_LI('Successfuly started conductor with hostname '
                         '%(hostname)s.'),
                     {'hostname': self.host})
        except exception.NoFreeConductorWorker:
            with excutils.save_and_reraise_exception():
                LOG.critical(_('Failed to start keepalive'))
                self.del_host()
Exemplo n.º 53
0
    def init_host(self):
        self.dbapi = dbapi.get_instance()

        self.driver_factory = driver_factory.DriverFactory()
        self.drivers = self.driver_factory.names
        """List of driver names which this conductor supports."""

        try:
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})
        except exception.ConductorAlreadyRegistered:
            LOG.warn(_("A conductor with hostname %(hostname)s "
                       "was previously registered. Updating registration")
                       % {'hostname': self.host})
            self.dbapi.unregister_conductor(self.host)
            self.dbapi.register_conductor({'hostname': self.host,
                                           'drivers': self.drivers})

        self.ring_manager = hash.HashRingManager()
        """Consistent hash ring which maps drivers to conductors."""

        self._worker_pool = greenpool.GreenPool(
                                size=CONF.conductor.workers_pool_size)
        """GreenPool of background workers for performing tasks async."""
Exemplo n.º 54
0
def create_test_allocation(**kw):
    allocation = get_test_allocation(**kw)
    if 'id' not in kw:
        del allocation['id']
    dbapi = db_api.get_instance()
    return dbapi.create_allocation(allocation)
Exemplo n.º 55
0
 def setUp(self):
     super(PXEValidateParametersTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
Exemplo n.º 56
0
 def setUp(self):
     super(TestNodeObject, self).setUp()
     self.fake_node = utils.get_test_node()
     self.dbapi = db_api.get_instance()
Exemplo n.º 57
0
def create_fake_node(i):
    dbh = dbapi.get_instance()
    node = utils.get_test_node(id=i, uuid=ironic_utils.generate_uuid())
    dbh.create_node(node)
    return node['uuid']
Exemplo n.º 58
0
class Allocation(base.IronicObject, object_base.VersionedObjectDictCompat):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'id': object_fields.IntegerField(),
        'uuid': object_fields.UUIDField(nullable=True),
        'name': object_fields.StringField(nullable=True),
        'node_id': object_fields.IntegerField(nullable=True),
        'state': object_fields.StringField(nullable=True),
        'last_error': object_fields.StringField(nullable=True),
        'resource_class': object_fields.StringField(nullable=True),
        'traits': object_fields.ListOfStringsField(nullable=True),
        'candidate_nodes': object_fields.ListOfStringsField(nullable=True),
        'extra': object_fields.FlexibleDictField(nullable=True),
        'conductor_affinity': object_fields.IntegerField(nullable=True),
    }

    def _convert_to_version(self,
                            target_version,
                            remove_unavailable_fields=True):
        """Convert to the target version.

        Convert the object to the target version. The target version may be
        the same, older, or newer than the version of the object. This is
        used for DB interactions as well as for serialization/deserialization.

        :param target_version: the desired version of the object
        :param remove_unavailable_fields: True to remove fields that are
            unavailable in the target version; set this to True when
            (de)serializing. False to set the unavailable fields to appropriate
            values; set this to False for DB interactions.
        """

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get(cls, context, allocation_ident):
        """Find an allocation by its ID, UUID or name.

        :param allocation_ident: The ID, UUID or name of an allocation.
        :param context: Security context
        :returns: An :class:`Allocation` object.
        :raises: InvalidIdentity

        """
        if strutils.is_int_like(allocation_ident):
            return cls.get_by_id(context, allocation_ident)
        elif uuidutils.is_uuid_like(allocation_ident):
            return cls.get_by_uuid(context, allocation_ident)
        elif utils.is_valid_logical_name(allocation_ident):
            return cls.get_by_name(context, allocation_ident)
        else:
            raise exception.InvalidIdentity(identity=allocation_ident)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_id(cls, context, allocation_id):
        """Find an allocation by its integer ID.

        :param cls: the :class:`Allocation`
        :param context: Security context
        :param allocation_id: The ID of an allocation.
        :returns: An :class:`Allocation` object.
        :raises: AllocationNotFound

        """
        db_allocation = cls.dbapi.get_allocation_by_id(allocation_id)
        allocation = cls._from_db_object(context, cls(), db_allocation)
        return allocation

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_uuid(cls, context, uuid):
        """Find an allocation by its UUID.

        :param cls: the :class:`Allocation`
        :param context: Security context
        :param uuid: The UUID of an allocation.
        :returns: An :class:`Allocation` object.
        :raises: AllocationNotFound

        """
        db_allocation = cls.dbapi.get_allocation_by_uuid(uuid)
        allocation = cls._from_db_object(context, cls(), db_allocation)
        return allocation

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_name(cls, context, name):
        """Find an allocation based by its name.

        :param cls: the :class:`Allocation`
        :param context: Security context
        :param name: The name of an allocation.
        :returns: An :class:`Allocation` object.
        :raises: AllocationNotFound

        """
        db_allocation = cls.dbapi.get_allocation_by_name(name)
        allocation = cls._from_db_object(context, cls(), db_allocation)
        return allocation

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def list(cls,
             context,
             filters=None,
             limit=None,
             marker=None,
             sort_key=None,
             sort_dir=None):
        """Return a list of Allocation objects.

        :param cls: the :class:`Allocation`
        :param context: Security context.
        :param filters: Filters to apply.
        :param limit: Maximum number of resources to return in a single result.
        :param marker: Pagination marker for large data sets.
        :param sort_key: Column to sort results by.
        :param sort_dir: Direction to sort. "asc" or "desc".
        :returns: A list of :class:`Allocation` object.
        :raises: InvalidParameterValue

        """
        db_allocations = cls.dbapi.get_allocation_list(filters=filters,
                                                       limit=limit,
                                                       marker=marker,
                                                       sort_key=sort_key,
                                                       sort_dir=sort_dir)
        return cls._from_db_object_list(context, db_allocations)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def create(self, context=None):
        """Create a Allocation record in the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Allocation(context)
        :raises: AllocationDuplicateName, AllocationAlreadyExists

        """
        values = self.do_version_changes_for_db()
        db_allocation = self.dbapi.create_allocation(values)
        self._from_db_object(self._context, self, db_allocation)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def destroy(self, context=None):
        """Delete the Allocation from the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Allocation(context)
        :raises: AllocationNotFound

        """
        self.dbapi.destroy_allocation(self.uuid)
        self.obj_reset_changes()

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def save(self, context=None):
        """Save updates to this Allocation.

        Updates will be made column by column based on the result
        of self.what_changed().

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Allocation(context)
        :raises: AllocationNotFound, AllocationDuplicateName

        """
        updates = self.do_version_changes_for_db()
        updated_allocation = self.dbapi.update_allocation(self.uuid, updates)
        self._from_db_object(self._context, self, updated_allocation)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def refresh(self, context=None):
        """Loads updates for this Allocation.

        Loads an allocation with the same uuid from the database and
        checks for updated attributes. Updates are applied from
        the loaded allocation column by column, if there are any updates.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Allocation(context)
        :raises: AllocationNotFound

        """
        current = self.get_by_uuid(self._context, uuid=self.uuid)
        self.obj_refresh(current)
        self.obj_reset_changes()
Exemplo n.º 59
0
class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat):
    # Version 1.0: Initial version
    # Version 1.1: Add internal_info field
    # Version 1.2: Add standalone_ports_supported field
    VERSION = '1.2'

    dbapi = dbapi.get_instance()

    fields = {
        'id': object_fields.IntegerField(),
        'uuid': object_fields.UUIDField(nullable=True),
        'name': object_fields.StringField(nullable=True),
        'node_id': object_fields.IntegerField(nullable=True),
        'address': object_fields.MACAddressField(nullable=True),
        'extra': object_fields.FlexibleDictField(nullable=True),
        'internal_info': object_fields.FlexibleDictField(nullable=True),
        'standalone_ports_supported': object_fields.BooleanField(),
    }

    @staticmethod
    def _from_db_object_list(db_objects, cls, context):
        """Converts a list of database entities to a list of formal objects."""
        return [Portgroup._from_db_object(cls(context), obj) for obj in
                db_objects]

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get(cls, context, portgroup_ident):
        """Find a portgroup based on its id, uuid, name or address.

        :param portgroup_ident: The id, uuid, name or address of a portgroup.
        :param context: Security context
        :returns: A :class:`Portgroup` object.
        :raises: InvalidIdentity

        """
        if strutils.is_int_like(portgroup_ident):
            return cls.get_by_id(context, portgroup_ident)
        elif uuidutils.is_uuid_like(portgroup_ident):
            return cls.get_by_uuid(context, portgroup_ident)
        elif utils.is_valid_mac(portgroup_ident):
            return cls.get_by_address(context, portgroup_ident)
        elif utils.is_valid_logical_name(portgroup_ident):
            return cls.get_by_name(context, portgroup_ident)
        else:
            raise exception.InvalidIdentity(identity=portgroup_ident)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_id(cls, context, portgroup_id):
        """Find a portgroup based on its integer id and return a Portgroup object.

        :param portgroup id: The id of a portgroup.
        :param context: Security context
        :returns: A :class:`Portgroup` object.
        :raises: PortgroupNotFound

        """
        db_portgroup = cls.dbapi.get_portgroup_by_id(portgroup_id)
        portgroup = Portgroup._from_db_object(cls(context), db_portgroup)
        return portgroup

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_uuid(cls, context, uuid):
        """Find a portgroup based on uuid and return a :class:`Portgroup` object.

        :param uuid: The uuid of a portgroup.
        :param context: Security context
        :returns: A :class:`Portgroup` object.
        :raises: PortgroupNotFound

        """
        db_portgroup = cls.dbapi.get_portgroup_by_uuid(uuid)
        portgroup = Portgroup._from_db_object(cls(context), db_portgroup)
        return portgroup

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_address(cls, context, address):
        """Find a portgroup based on address and return a :class:`Portgroup` object.

        :param address: The MAC address of a portgroup.
        :param context: Security context
        :returns: A :class:`Portgroup` object.
        :raises: PortgroupNotFound

        """
        db_portgroup = cls.dbapi.get_portgroup_by_address(address)
        portgroup = Portgroup._from_db_object(cls(context), db_portgroup)
        return portgroup

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_name(cls, context, name):
        """Find a portgroup based on name and return a :class:`Portgroup` object.

        :param name: The name of a portgroup.
        :param context: Security context
        :returns: A :class:`Portgroup` object.
        :raises: PortgroupNotFound

        """
        db_portgroup = cls.dbapi.get_portgroup_by_name(name)
        portgroup = Portgroup._from_db_object(cls(context), db_portgroup)
        return portgroup

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def list(cls, context, limit=None, marker=None,
             sort_key=None, sort_dir=None):
        """Return a list of Portgroup objects.

        :param context: Security context.
        :param limit: Maximum number of resources to return in a single result.
        :param marker: Pagination marker for large data sets.
        :param sort_key: Column to sort results by.
        :param sort_dir: Direction to sort. "asc" or "desc".
        :returns: A list of :class:`Portgroup` object.
        :raises: InvalidParameterValue

        """
        db_portgroups = cls.dbapi.get_portgroup_list(limit=limit,
                                                     marker=marker,
                                                     sort_key=sort_key,
                                                     sort_dir=sort_dir)
        return Portgroup._from_db_object_list(db_portgroups, cls, context)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def list_by_node_id(cls, context, node_id, limit=None, marker=None,
                        sort_key=None, sort_dir=None):
        """Return a list of Portgroup objects associated with a given node ID.

        :param context: Security context.
        :param node_id: The ID of the node.
        :param limit: Maximum number of resources to return in a single result.
        :param marker: Pagination marker for large data sets.
        :param sort_key: Column to sort results by.
        :param sort_dir: Direction to sort. "asc" or "desc".
        :returns: A list of :class:`Portgroup` object.
        :raises: InvalidParameterValue

        """
        db_portgroups = cls.dbapi.get_portgroups_by_node_id(node_id,
                                                            limit=limit,
                                                            marker=marker,
                                                            sort_key=sort_key,
                                                            sort_dir=sort_dir)
        return Portgroup._from_db_object_list(db_portgroups, cls, context)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def create(self, context=None):
        """Create a Portgroup record in the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Portgroup(context)
        :raises: DuplicateName, MACAlreadyExists, PortgroupAlreadyExists

        """
        values = self.obj_get_changes()
        db_portgroup = self.dbapi.create_portgroup(values)
        self._from_db_object(self, db_portgroup)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def destroy(self, context=None):
        """Delete the Portgroup from the DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Portgroup(context)
        :raises: PortgroupNotEmpty, PortgroupNotFound

        """
        self.dbapi.destroy_portgroup(self.uuid)
        self.obj_reset_changes()

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def save(self, context=None):
        """Save updates to this Portgroup.

        Updates will be made column by column based on the result
        of self.what_changed().

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Portgroup(context)
        :raises: PortgroupNotFound, DuplicateName, MACAlreadyExists

        """
        updates = self.obj_get_changes()
        updated_portgroup = self.dbapi.update_portgroup(self.uuid, updates)
        self._from_db_object(self, updated_portgroup)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable
    def refresh(self, context=None):
        """Loads updates for this Portgroup.

        Loads a portgroup with the same uuid from the database and
        checks for updated attributes. Updates are applied from
        the loaded portgroup column by column, if there are any updates.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Portgroup(context)
        :raises: PortgroupNotFound

        """
        current = self.__class__.get_by_uuid(self._context, uuid=self.uuid)
        self.obj_refresh(current)
Exemplo n.º 60
0
 def setUp(self):
     super(SqlAlchemyCustomTypesTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()