def test__get_client_with_auth_token(self, mock_ir_cli):
     self.flags(admin_auth_token='fake-token', group='ironic')
     ironicclient = client_wrapper.IronicClientWrapper()
     # dummy call to have _get_client() called
     ironicclient.call("node.list")
     expected = {
         'os_auth_token': 'fake-token',
         'ironic_url': CONF.ironic.api_endpoint
     }
     mock_ir_cli.assert_called_once_with(CONF.ironic.api_version,
                                         **expected)
 def test__get_client_no_auth_token(self, mock_ir_cli):
     self.flags(admin_auth_token=None, group='ironic')
     ironicclient = client_wrapper.IronicClientWrapper()
     # dummy call to have _get_client() called
     ironicclient.call("node.list")
     expected = {
         'os_username': CONF.ironic.admin_username,
         'os_password': CONF.ironic.admin_password,
         'os_auth_url': CONF.ironic.admin_url,
         'os_tenant_name': CONF.ironic.admin_tenant_name,
         'os_service_type': 'baremetal',
         'os_endpoint_type': 'public',
         'ironic_url': CONF.ironic.api_endpoint
     }
     mock_ir_cli.assert_called_once_with(CONF.ironic.api_version,
                                         **expected)
Example #3
0
    def __init__(self, flavor_filter, image_filter, glance_auth_token_func,
                 known_flavors):
        """Constructs an OpenstackScout object.

        :param: flavor_filter - A function that should return True for
            flavors which the scout should include when
            returning information bound for Strategy objects. Returning
            False will cause the scout to ignore nodes of that flavor.
        :param: image_filter - A functiion which should return True for images
            to use for caching, and False for those to ignore. The function
            will accept a single argument of a Python'd JSON flavor as
            returned by a Nova flavor-list request.
        :param: glance_auth_token_func - A function which will return an
            authorization token for the Glance client to use for authenticating
            requests. It should accept the following keyword arguments:
                auth_url - The url to request the token from.
                username - Username for token request.
                password - Password for token request.
            See the GlanceClientWrapper class for more information about which
            keyword arguments will be sent to this function. This function
            could potentially ignore the keyword arguments if the function is
            able to authorize through other means.
        :param: known_flavors - A dictionary mapping flavor names (strings)
            to identity functions. This allows a user to supply their own
            identification functions. Each function will be fed one
            argument: The ironic_node param listed above. The 'first'
            identity function that returns True will identify the flavor
            of the node.
        """
        self.flavor_filter = flavor_filter
        self.image_filter = image_filter
        self.ironic_client = icw.IronicClientWrapper()
        self.nova_client = ncw.NovaClientWrapper()
        self.glance_client = gcw.GlanceClientWrapper(glance_auth_token_func)
        self.glance_data = []
        self.known_flavors = copy.deepcopy(known_flavors)

        def curried_convert_ironic_node(ironic_node):
            return convert_ironic_node(ironic_node, self.known_flavors)

        self.curried_convert_ironic_node = curried_convert_ironic_node

        def curried_convert_nova_flavor(nova_flavor):
            return convert_nova_flavor(nova_flavor, self.known_flavors)

        self.curried_convert_nova_flavor = curried_convert_nova_flavor
 def setUp(self):
     super(IronicClientWrapperTestCase, self).setUp()
     self.ironicclient = client_wrapper.IronicClientWrapper()
     # Do not waste time sleeping
     cfg.CONF.set_override('call_retry_interval', 0, 'client_wrapper')