Skip to content

Update RMS models and API #445

Update RMS models and API

Update RMS models and API #445

GitHub Actions / Test Report ubuntu-latest:3.10 failed Dec 22, 2023 in 0s

75 tests run, 71 passed, 3 skipped, 1 failed.

Annotations

Check failure on line 1 in TaskDefinitionTemplateTest

See this annotation in the file changed.

@github-actions github-actions / Test Report ubuntu-latest:3.10

TaskDefinitionTemplateTest.test_template_integration

ansys.hps.client.exceptions.ClientError: 400 Client Error: Template (new_template_37072d4e-6d84-4a04-9512-18e72cf620a2 - 1.0) already exists for: PUT https://localhost:8443/rep/jms/api/v1/task_definition_templates?fields=all
Raw output
self = <tests.jms.test_task_definition_templates.TaskDefinitionTemplateTest testMethod=test_template_integration>

    def test_template_integration(self):
    
        client = self.client
        jms_api = JmsApi(client)
    
        # Test get queries
        templates = jms_api.get_task_definition_templates()
        self.assertGreater(len(templates), 0)
        self.assertTrue(templates[0].id is not None)
    
        templates = jms_api.get_task_definition_templates(as_objects=False)
        self.assertGreater(len(templates), 0)
        self.assertTrue(templates[0]["id"] is not None)
    
        templates = jms_api.get_task_definition_templates(
            as_objects=False, fields=["name", "software_requirements"]
        )
        self.assertGreater(len(templates), 0)
        log.info(f"templates={json.dumps(templates, indent=4)}")
        if templates:
            self.assertTrue("software_requirements" in templates[0].keys())
            self.assertTrue("name" in templates[0]["software_requirements"][0].keys())
            self.assertTrue("version" in templates[0]["software_requirements"][0].keys())
    
        templates = jms_api.get_task_definition_templates(fields=["name"])
        if templates:
            self.assertTrue(templates[0].software_requirements == missing)
    
        # Create new template based on existing one
        template_name = f"new_template_{uuid.uuid4()}"
        templates = jms_api.get_task_definition_templates(limit=1)
        self.assertEqual(len(templates), 1)
    
        template = TaskDefinitionTemplate(
            name=template_name, software_requirements=templates[0].software_requirements
        )
        template.version = "1.0"
        templates = jms_api.create_task_definition_templates([template])
        self.assertEqual(len(templates), 1)
        template = templates[0]
        self.assertEqual(template.name, template_name)
    
        # Modify template
        template.software_requirements[0].version = "2.0.1"
        template.resource_requirements = TemplateResourceRequirements(
            hpc_resources=HpcResources(num_gpus_per_node=2)
        )
>       templates = jms_api.update_task_definition_templates([template])

tests/jms/test_task_definition_templates.py:144: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/py310-noeval-coverage/lib/python3.10/site-packages/ansys/hps/client/jms/api/jms_api.py:143: in update_task_definition_templates
    return update_objects(
.tox/py310-noeval-coverage/lib/python3.10/site-packages/ansys/hps/client/jms/api/base.py:103: in update_objects
    r = session.put(f"{url}", data=json_data, params=query_params)
.tox/py310-noeval-coverage/lib/python3.10/site-packages/requests/sessions.py:649: in put
    return self.request("PUT", url, data=data, **kwargs)
.tox/py310-noeval-coverage/lib/python3.10/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
.tox/py310-noeval-coverage/lib/python3.10/site-packages/requests/sessions.py:710: in send
    r = dispatch_hook("response", hooks, r, **kwargs)
.tox/py310-noeval-coverage/lib/python3.10/site-packages/requests/hooks.py:30: in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

response = <Response [400]>, args = ()
kwargs = {'cert': None, 'proxies': OrderedDict(), 'stream': False, 'timeout': None, ...}
r_content = {'title': 'Template (new_template_37072d4e-6d84-4a04-9512-18e72cf620a2 - 1.0) already exists'}
reason = 'Template (new_template_37072d4e-6d84-4a04-9512-18e72cf620a2 - 1.0) already exists'
description = None
error_msg = '400 Client Error: Template (new_template_37072d4e-6d84-4a04-9512-18e72cf620a2 - 1.0) already exists for: PUT https://localhost:8443/rep/jms/api/v1/task_definition_templates?fields=all'

    def raise_for_status(response, *args, **kwargs):
        """Hook function to automatically check HTTP errors.
        Mimics requests.Response.raise_for_status()"""
        if 400 <= response.status_code < 600:
    
            r_content = {}
            try:
                r_content = response.json()
            except ValueError:
                pass
    
            reason = r_content.get("title", None)  # jms api
            if not reason:
                reason = r_content.get("error", None)  # auth api
            if not reason:
                reason = response.reason
    
            description = r_content.get("description", None)  # jms api
            if not description:
                description = r_content.get("error_description", None)  # auth api
    
            if 400 <= response.status_code < 500:
                error_msg = "%s Client Error: %s for: %s %s" % (
                    response.status_code,
                    reason,
                    response.request.method,
                    response.url,
                )
                if description:
                    error_msg += f"\n{description}"
>               raise ClientError(error_msg, reason=reason, description=description, response=response)
E               ansys.hps.client.exceptions.ClientError: 400 Client Error: Template (new_template_37072d4e-6d84-4a04-9512-18e72cf620a2 - 1.0) already exists for: PUT https://localhost:8443/rep/jms/api/v1/task_definition_templates?fields=all

.tox/py310-noeval-coverage/lib/python3.10/site-packages/ansys/hps/client/exceptions.py:76: ClientError