Exemple #1
0
 def test_create_region_validate_any_error(self, mock_db_get_group,
                                           mock_get_region_id_name):
     message = None
     try:
         result = services.create_full_region(
             self._to_wsme_from_input(full_region))
     except Exception as exp:
         message = exp.message
     self.assertEqual(message, "any")
Exemple #2
0
 def test_create_region_duplicate(self, mock_db_create_region,
                                  mock_get_region_id_name):
     duplicate = mock.MagicMock()
     duplicate.side_effect = services.base_data_manager.DuplicateEntryError(
     )
     mock_db_create_region.return_value.add_region = duplicate
     with self.assertRaises(services.error_base.ConflictError) as exp:
         result = services.create_full_region(
             self._to_wsme_from_input(full_region))
Exemple #3
0
 def test_create_region_validate_status_error(self, mock_db_get_group,
                                              mock_get_region_id_name):
     orig_status = full_region['status']
     full_region['status'] = "123"
     allowed_status = conf.region_options.allowed_status_values[:]
     with self.assertRaises(services.error_base.InputValueError) as exp:
         result = services.create_full_region(
             self._to_wsme_from_input(full_region))
         test_ok = str(allowed_status) in exp.expected.message
         self.assertEqual(test_ok, True)
     full_region['status'] = orig_status
Exemple #4
0
 def test_create_region_validate_endpoints_error(self, mock_db_get_group,
                                                 mock_get_region_id_name):
     message = ""
     endpoints_types_must_have = conf.region_options.endpoints_types_must_have[:]
     orig_endpoint = full_region['endpoints']
     full_region['endpoints'] = [{
         "type": "dashboards",
         "publicURL": "http://horizon1.com"
     }]
     try:
         result = services.create_full_region(
             self._to_wsme_from_input(full_region))
     except services.error_base.InputValueError as exp:
         message = exp.message
     full_region['endpoints'] = orig_endpoint
     self.assertEqual(str(endpoints_types_must_have) in str(message), True)
Exemple #5
0
    def post(self, full_region_input):
        logger.info("API: CreateRegion")
        authentication.authorize(request, 'region:create')

        try:
            logger.debug(
                "API: create region .. data = : {}".format(full_region_input))
            result = RegionService.create_full_region(full_region_input)
            logger.debug("API: region created : {}".format(result))

            event_details = 'Region {} {} created: AICversion {}, OSversion {}, CLLI {}'.format(
                full_region_input.name, full_region_input.design_type,
                full_region_input.ranger_agent_version,
                full_region_input.open_stack_version, full_region_input.clli)
            utils.audit_trail('create region',
                              request.transaction_id,
                              request.headers,
                              full_region_input.id,
                              event_details=event_details)
        except error_base.InputValueError as exp:
            logger.exception("Error in save region {}".format(exp.message))
            raise err_utils.get_error(request.transaction_id,
                                      status_code=exp.status_code,
                                      message=exp.message)

        except error_base.ConflictError as exp:
            logger.exception("Conflict error {}".format(exp.message))
            raise err_utils.get_error(request.transaction_id,
                                      message=exp.message,
                                      status_code=exp.status_code)

        except Exception as exp:
            logger.exception(
                "Error in creating region .. reason:- {}".format(exp))
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      message=exp.message)

        return result
Exemple #6
0
 def test_create_region_success(self, mock_db_get_group,
                                mock_get_region_id_name):
     result = services.create_full_region(
         self._to_wsme_from_input(full_region))
     self.assertEqual(result, {"a": "b"})