Ejemplo n.º 1
0
 def test_with_successful_callbacks(self):
     rack = factory.make_RackController()
     getClientFor = self.patch(utils, "getClientFor")
     getClientFor.return_value = lambda: None
     partial = self.patch(utils, "partial")
     partial.return_value = sentinel.partial
     async_gather = self.patch(asynchronous, "gatherCallResults")
     async_gather.return_value = (result for result in [(sentinel.partial,
                                                         sentinel.result)])
     available_callback = Mock()
     unavailable_callback = Mock()
     success_callback = Mock()
     failed_callback = Mock()
     timeout_callback = Mock()
     result = list(
         utils.call_clusters(
             sentinel.command,
             available_callback=available_callback,
             unavailable_callback=unavailable_callback,
             success_callback=success_callback,
             failed_callback=failed_callback,
             timeout_callback=timeout_callback,
         ))
     self.assertThat(result, Equals([sentinel.result]))
     self.assertThat(available_callback, MockCalledOnceWith(rack))
     self.assertThat(unavailable_callback, MockNotCalled())
     self.assertThat(success_callback, MockCalledOnceWith(rack))
     self.assertThat(failed_callback, MockNotCalled())
     self.assertThat(timeout_callback, MockNotCalled())
Ejemplo n.º 2
0
 def test_with_unavailable_callbacks(self):
     logger = self.useFixture(FakeLogger("maasserver"))
     rack = factory.make_RackController()
     getClientFor = self.patch(utils, "getClientFor")
     getClientFor.side_effect = NoConnectionsAvailable
     partial = self.patch(utils, "partial")
     partial.return_value = sentinel.partial
     async_gather = self.patch(asynchronous, "gatherCallResults")
     async_gather.return_value = iter([])
     available_callback = Mock()
     unavailable_callback = Mock()
     success_callback = Mock()
     failed_callback = Mock()
     timeout_callback = Mock()
     result = list(
         utils.call_clusters(
             sentinel.command,
             available_callback=available_callback,
             unavailable_callback=unavailable_callback,
             success_callback=success_callback,
             failed_callback=failed_callback,
             timeout_callback=timeout_callback,
         ))
     self.assertThat(result, Equals([]))
     self.assertThat(available_callback, MockNotCalled())
     self.assertThat(unavailable_callback, MockCalledOnceWith(rack))
     self.assertThat(success_callback, MockNotCalled())
     self.assertThat(failed_callback, MockNotCalled())
     self.assertThat(timeout_callback, MockNotCalled())
     self.assertThat(logger.output,
                     DocTestMatches("...Unable to get RPC connection..."))
Ejemplo n.º 3
0
 def test_with_failed_callbacks(self):
     logger = self.useFixture(FakeLogger("maasserver"))
     rack = factory.make_RackController()
     getClientFor = self.patch(utils, "getClientFor")
     getClientFor.return_value = lambda: None
     partial = self.patch(utils, "partial")
     partial.return_value = sentinel.partial
     async_gather = self.patch(asynchronous, "gatherCallResults")
     async_gather.return_value = (result for result in [(sentinel.partial,
                                                         MockFailure())])
     available_callback = Mock()
     unavailable_callback = Mock()
     success_callback = Mock()
     failed_callback = Mock()
     timeout_callback = Mock()
     result = list(
         utils.call_clusters(
             sentinel.command,
             available_callback=available_callback,
             unavailable_callback=unavailable_callback,
             success_callback=success_callback,
             failed_callback=failed_callback,
             timeout_callback=timeout_callback,
         ))
     self.assertThat(result, Equals([]))
     self.assertThat(available_callback, MockCalledOnceWith(rack))
     self.assertThat(unavailable_callback, MockNotCalled())
     self.assertThat(success_callback, MockNotCalled())
     self.assertThat(failed_callback, MockCalledOnceWith(rack))
     self.assertThat(timeout_callback, MockNotCalled())
     self.assertThat(
         logger.output,
         DocTestMatches(
             "Exception during ... on rack controller...MockFailure: ..."),
     )
Ejemplo n.º 4
0
def get_all_nos_types_from_racks(controllers=None, ignore_errors=True):
    """Query every rack controller and obtain all known NOS driver types.

    :return: a list of power types matching the schema
        provisioningserver.drivers.nos.JSON_NOS_DRIVERS_SCHEMA.
    """
    merged_types = []
    responses = call_clusters(
        cluster.DescribeNOSTypes,
        controllers=controllers,
        ignore_errors=ignore_errors,
    )
    for response in responses:
        nos_types = response["nos_types"]
        for nos_type in nos_types:
            driver_type = nos_type.get("driver_type", "nos")
            name = nos_type["name"]
            fields = nos_type.get("fields", [])
            description = nos_type["description"]
            deployable = nos_type.get("deployable")
            add_nos_driver_parameters(
                driver_type,
                name,
                description,
                fields,
                merged_types,
                deployable=deployable,
            )
    validate(merged_types, JSON_NOS_DRIVERS_SCHEMA)
    return sorted(merged_types, key=itemgetter("description"))
Ejemplo n.º 5
0
def get_all_power_types_from_racks(controllers=None, ignore_errors=True):
    """Query every rack controller and obtain all known power driver types.

    :return: a list of power types matching the schema
        provisioningserver.drivers.power.JSON_POWER_DRIVERS_SCHEMA or
        provisioningserver.drivers.pod.JSON_POD_DRIVERS_SCHEMA
    """
    merged_types = []
    responses = call_clusters(cluster.DescribePowerTypes,
                              controllers=controllers,
                              ignore_errors=ignore_errors)
    for response in responses:
        power_types = response['power_types']
        for power_type in power_types:
            driver_type = power_type.get('driver_type', 'power')
            name = power_type['name']
            fields = power_type.get('fields', [])
            description = power_type['description']
            missing_packages = power_type['missing_packages']
            queryable = power_type.get('queryable')
            add_driver_parameters(driver_type,
                                  name,
                                  description,
                                  fields,
                                  missing_packages,
                                  merged_types,
                                  queryable=queryable)
    return sorted(merged_types, key=itemgetter("description"))
Ejemplo n.º 6
0
    def test_gets_clients(self):
        rack = factory.make_RackController()
        getClientFor = self.patch(utils, "getClientFor")
        getClientFor.return_value = lambda: None
        async_gather = self.patch(asynchronous, "gatherCallResults")
        async_gather.return_value = []

        # call_clusters returns with nothing because we patched out
        # asynchronous.gather, but we're interested in the side-effect:
        # getClientFor has been called for the accepted nodegroup.
        self.assertItemsEqual([], utils.call_clusters(sentinel.command))
        self.assertThat(getClientFor, MockCalledOnceWith(rack.system_id))
Ejemplo n.º 7
0
def list_supported_architectures():
    """List the architecture choices supported by this cluster controller.

    These are all architectures that the cluster controller could conceivably
    deal with, regardless of whether the controller has images for them.

    :return: An :class:`OrderedDict` of choices.
    """
    results = call_clusters(cluster.ListSupportedArchitectures)
    all_arches = []
    for result in results:
        all_arches += [(arch["name"], arch["description"])
                       for arch in result["architectures"]]
    return OrderedDict(sorted(all_arches))