def test_failed_to_validate_node(self, client_mock, start_mock): cli = client_mock.return_value cli.get_node.return_value = self.node cli.validate_node.side_effect = os_exc.ValidationException() self.assertRaisesRegex( utils.Error, 'Failed validation of power interface: ValidationException', introspect.introspect, self.uuid) cli.validate_node.assert_called_once_with(self.uuid, required='power') self.assertEqual(0, self.node_info.ports.call_count) self.assertEqual(0, self.sync_filter_mock.call_count) self.assertEqual(0, cli.set_node_power_state.call_count) self.assertFalse(start_mock.called) self.assertFalse(self.node_info.acquire_lock.called)
def validate(self, session, required=('boot', 'deploy', 'power')): """Validate required information on a node. :param session: The session to use for making this request. :type session: :class:`~keystoneauth1.adapter.Adapter` :param required: List of interfaces that are required to pass validation. The default value is the list of minimum required interfaces for provisioning. :return: dict mapping interface names to :class:`ValidationResult` objects. :raises: :exc:`~openstack.exceptions.ValidationException` if validation fails for a required interface. """ session = self._get_session(session) version = self._get_microversion_for(session, 'fetch') request = self._prepare_request(requires_id=True) request.url = utils.urljoin(request.url, 'validate') response = session.get(request.url, headers=request.headers, microversion=version) msg = ("Failed to validate node {node}".format(node=self.id)) exceptions.raise_from_response(response, error_message=msg) result = response.json() if required: failed = [ '%s (%s)' % (key, value.get('reason', 'no reason')) for key, value in result.items() if key in required and not value.get('result') ] if failed: raise exceptions.ValidationException( 'Validation failed for required interfaces of node {node}:' ' {failures}'.format(node=self.id, failures=', '.join(failed))) return { key: ValidationResult(value.get('result'), value.get('reason')) for key, value in result.items() }