Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Computer and add --format option to verdi computer show #3616

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions aiida/backends/tests/cmdline/commands/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def test_interactive_remote(self):
os.environ['EDITOR'] = 'sleep 1; vim -cwq'
label = 'interactive_remote'
user_input = '\n'.join(
[label, 'description', 'arithmetic.add', 'yes', self.comp.name, '/remote/abs/path'])
[label, 'description', 'arithmetic.add', 'yes', self.comp.label, '/remote/abs/path'])
result = self.cli_runner.invoke(setup_code, input=user_input)
self.assertClickResultNoException(result)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.name)), Code)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.label)), Code)

def test_interactive_upload(self):
from aiida.orm import Code
Expand All @@ -74,12 +74,12 @@ def test_noninteractive_remote(self):
label = 'noninteractive_remote'
options = [
'--non-interactive', '--label={}'.format(label), '--description=description',
'--input-plugin=arithmetic.add', '--on-computer', '--computer={}'.format(self.comp.name),
'--input-plugin=arithmetic.add', '--on-computer', '--computer={}'.format(self.comp.label),
'--remote-abs-path=/remote/abs/path'
]
result = self.cli_runner.invoke(setup_code, options)
self.assertClickResultNoException(result)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.name)), Code)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.label)), Code)

def test_noninteractive_upload(self):
from aiida.orm import Code
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_from_config(self):
input_plugin: arithmetic.add
computer: {c}
remote_abs_path: /remote/abs/path
""".format(l=label, c=self.comp.name))
""".format(l=label, c=self.comp.label))
handle.flush()
result = self.cli_runner.invoke(setup_code, ['--non-interactive', '--config', os.path.realpath(handle.name)])

Expand All @@ -118,10 +118,10 @@ def test_mixed(self):
from aiida.orm import Code
label = 'mixed_remote'
options = ['--description=description', '--on-computer', '--remote-abs-path=/remote/abs/path']
user_input = '\n'.join([label, 'arithmetic.add', self.comp.name])
user_input = '\n'.join([label, 'arithmetic.add', self.comp.label])
result = self.cli_runner.invoke(setup_code, options, input=user_input)
self.assertClickResultNoException(result)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.name)), Code)
self.assertIsInstance(Code.get_from_string('{}@{}'.format(label, self.comp.label)), Code)


class TestVerdiCodeCommands(AiidaTestCase):
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_code_list(self):
code.store()

options = [
'-A', '-a', '-o', '--input-plugin=arithmetic.add', '--computer={}'.format(self.comp.name)
'-A', '-a', '-o', '--input-plugin=arithmetic.add', '--computer={}'.format(self.comp.label)
]
result = self.cli_runner.invoke(code_list, options)
self.assertIsNone(result.exception, result.output)
Expand Down
111 changes: 65 additions & 46 deletions aiida/backends/tests/cmdline/commands/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands.cmd_computer import computer_disable, computer_enable, computer_setup
from aiida.cmdline.commands.cmd_computer import computer_setup
from aiida.cmdline.commands.cmd_computer import computer_show, computer_list, computer_rename, computer_delete
from aiida.cmdline.commands.cmd_computer import computer_test, computer_configure, computer_duplicate

Expand Down Expand Up @@ -132,15 +132,15 @@ def test_interactive(self):

self.assertEqual(new_computer.description, options_dict['description'])
self.assertEqual(new_computer.hostname, options_dict['hostname'])
self.assertEqual(new_computer.get_transport_type(), options_dict['transport'])
self.assertEqual(new_computer.get_scheduler_type(), options_dict['scheduler'])
self.assertEqual(new_computer.get_mpirun_command(), options_dict['mpirun-command'].split())
self.assertEqual(new_computer.get_shebang(), options_dict['shebang'])
self.assertEqual(new_computer.get_workdir(), options_dict['work-dir'])
self.assertEqual(new_computer.get_default_mpiprocs_per_machine(), int(options_dict['mpiprocs-per-machine']))
self.assertEqual(new_computer.transport_type, options_dict['transport'])
self.assertEqual(new_computer.scheduler_type, options_dict['scheduler'])
self.assertEqual(new_computer.get_property('mpirun_command'), options_dict['mpirun-command'].split())
self.assertEqual(new_computer.get_property('shebang'), options_dict['shebang'])
self.assertEqual(new_computer.get_property('work_dir'), options_dict['work-dir'])
self.assertEqual(new_computer.get_property('default_mpiprocs_per_machine'), int(options_dict['mpiprocs-per-machine']))
# For now I'm not writing anything in them
self.assertEqual(new_computer.get_prepend_text(), '')
self.assertEqual(new_computer.get_append_text(), '')
self.assertEqual(new_computer.get_property('prepend_text'), '')
self.assertEqual(new_computer.get_property('append_text'), '')

def test_mixed(self):
os.environ['VISUAL'] = 'sleep 1; vim -cwq'
Expand Down Expand Up @@ -170,16 +170,16 @@ def test_mixed(self):

self.assertEqual(new_computer.description, options_dict_full['description'])
self.assertEqual(new_computer.hostname, options_dict_full['hostname'])
self.assertEqual(new_computer.get_transport_type(), options_dict_full['transport'])
self.assertEqual(new_computer.get_scheduler_type(), options_dict_full['scheduler'])
self.assertEqual(new_computer.get_mpirun_command(), options_dict_full['mpirun-command'].split())
self.assertEqual(new_computer.get_shebang(), options_dict_full['shebang'])
self.assertEqual(new_computer.get_workdir(), options_dict_full['work-dir'])
self.assertEqual(new_computer.get_default_mpiprocs_per_machine(),
self.assertEqual(new_computer.transport_type, options_dict_full['transport'])
self.assertEqual(new_computer.scheduler_type, options_dict_full['scheduler'])
self.assertEqual(new_computer.get_property('mpirun_command'), options_dict_full['mpirun-command'].split())
self.assertEqual(new_computer.get_property('shebang'), options_dict_full['shebang'])
self.assertEqual(new_computer.get_property('work_dir'), options_dict_full['work-dir'])
self.assertEqual(new_computer.get_property('default_mpiprocs_per_machine'),
int(options_dict_full['mpiprocs-per-machine']))
# For now I'm not writing anything in them
self.assertEqual(new_computer.get_prepend_text(), options_dict_full['prepend-text'])
self.assertEqual(new_computer.get_append_text(), options_dict_full['append-text'])
self.assertEqual(new_computer.get_property('prepend_text'), options_dict_full['prepend-text'])
self.assertEqual(new_computer.get_property('append_text'), options_dict_full['append-text'])

def test_noninteractive(self):
"""
Expand All @@ -196,14 +196,14 @@ def test_noninteractive(self):

self.assertEqual(new_computer.description, options_dict['description'])
self.assertEqual(new_computer.hostname, options_dict['hostname'])
self.assertEqual(new_computer.get_transport_type(), options_dict['transport'])
self.assertEqual(new_computer.get_scheduler_type(), options_dict['scheduler'])
self.assertEqual(new_computer.get_mpirun_command(), options_dict['mpirun-command'].split())
self.assertEqual(new_computer.get_shebang(), options_dict['shebang'])
self.assertEqual(new_computer.get_workdir(), options_dict['work-dir'])
self.assertEqual(new_computer.get_default_mpiprocs_per_machine(), int(options_dict['mpiprocs-per-machine']))
self.assertEqual(new_computer.get_prepend_text(), options_dict['prepend-text'])
self.assertEqual(new_computer.get_append_text(), options_dict['append-text'])
self.assertEqual(new_computer.transport_type, options_dict['transport'])
self.assertEqual(new_computer.scheduler_type, options_dict['scheduler'])
self.assertEqual(new_computer.get_property('mpirun_command'), options_dict['mpirun-command'].split())
self.assertEqual(new_computer.get_property('shebang'), options_dict['shebang'])
self.assertEqual(new_computer.get_property('work_dir'), options_dict['work-dir'])
self.assertEqual(new_computer.get_property('default_mpiprocs_per_machine'), int(options_dict['mpiprocs-per-machine']))
self.assertEqual(new_computer.get_property('prepend_text'), options_dict['prepend-text'])
self.assertEqual(new_computer.get_property('append_text'), options_dict['append-text'])

# Test that I cannot generate twice a computer with the same label
result = self.cli_runner.invoke(computer_setup, options)
Expand All @@ -223,7 +223,7 @@ def test_noninteractive_optional_default_mpiprocs(self):

new_computer = orm.Computer.objects.get(name=options_dict['label'])
self.assertIsInstance(new_computer, orm.Computer)
self.assertIsNone(new_computer.get_default_mpiprocs_per_machine())
self.assertIsNone(new_computer.get_property('default_mpiprocs_per_machine'))

def test_noninteractive_optional_default_mpiprocs_2(self):
"""
Expand All @@ -238,7 +238,7 @@ def test_noninteractive_optional_default_mpiprocs_2(self):

new_computer = orm.Computer.objects.get(name=options_dict['label'])
self.assertIsInstance(new_computer, orm.Computer)
self.assertIsNone(new_computer.get_default_mpiprocs_per_machine())
self.assertIsNone(new_computer.get_property('default_mpiprocs_per_machine'))

def test_noninteractive_optional_default_mpiprocs_3(self):
"""
Expand Down Expand Up @@ -318,6 +318,25 @@ def test_noninteractive_from_config(self):
self.assertClickResultNoException(result)
self.assertIsInstance(orm.Computer.objects.get(name=label), orm.Computer)

def test_show_yaml(self):
"""Test round-trip of `verdi computer show --format yaml` with `verdi computer setup`."""
self.computer.set_property('default_mpiprocs_per_machine', 1)
options = ['--format', 'yaml', '--', self.computer.pk]
result = self.cli_runner.invoke(computer_show, options)
self.assertClickResultNoException(result)

# Rename the existing computer otherwise the setup command will fail
self.computer.label = self.computer.label + '_backup'

# Create a temporary file with the yaml formatted output and use it to setup a computer
yaml_config = result.stdout_bytes
with tempfile.NamedTemporaryFile() as handle:
handle.write(yaml_config)
handle.flush()
handle.seek(0)
result = self.cli_runner.invoke(computer_setup, ['--non-interactive', '--config', handle.name])
self.assertClickResultNoException(result)


class TestVerdiComputerConfigure(AiidaTestCase):

Expand Down Expand Up @@ -500,7 +519,7 @@ def setUpClass(cls, *args, **kwargs):
transport_type='local',
scheduler_type='direct',
workdir='/tmp/aiida')
cls.comp.set_default_mpiprocs_per_machine(1)
cls.comp.set_property('default_mpiprocs_per_machine', 1)
cls.comp.store()

def setUp(self):
Expand Down Expand Up @@ -656,15 +675,15 @@ def test_computer_duplicate_interactive(self):

new_computer = orm.Computer.objects.get(name=label)
self.assertEqual(self.comp.description, new_computer.description)
self.assertEqual(self.comp.get_hostname(), new_computer.get_hostname())
self.assertEqual(self.comp.get_transport_type(), new_computer.get_transport_type())
self.assertEqual(self.comp.get_scheduler_type(), new_computer.get_scheduler_type())
self.assertEqual(self.comp.get_shebang(), new_computer.get_shebang())
self.assertEqual(self.comp.get_workdir(), new_computer.get_workdir())
self.assertEqual(self.comp.get_mpirun_command(), new_computer.get_mpirun_command())
self.assertEqual(self.comp.get_default_mpiprocs_per_machine(), new_computer.get_default_mpiprocs_per_machine())
self.assertEqual(self.comp.get_prepend_text(), new_computer.get_prepend_text())
self.assertEqual(self.comp.get_append_text(), new_computer.get_append_text())
self.assertEqual(self.comp.hostname, new_computer.hostname)
self.assertEqual(self.comp.transport_type, new_computer.transport_type)
self.assertEqual(self.comp.scheduler_type, new_computer.scheduler_type)
self.assertEqual(self.comp.get_property('shebang'), new_computer.get_property('shebang'))
self.assertEqual(self.comp.get_property('work_dir'), new_computer.get_property('work_dir'))
self.assertEqual(self.comp.get_property('mpirun_command'), new_computer.get_property('mpirun_command'))
self.assertEqual(self.comp.get_property('default_mpiprocs_per_machine'), new_computer.get_property('default_mpiprocs_per_machine'))
self.assertEqual(self.comp.get_property('prepend_text'), new_computer.get_property('prepend_text'))
self.assertEqual(self.comp.get_property('append_text'), new_computer.get_property('append_text'))

def test_computer_duplicate_non_interactive(self):
label = 'computer_duplicate_noninteractive'
Expand All @@ -674,12 +693,12 @@ def test_computer_duplicate_non_interactive(self):

new_computer = orm.Computer.objects.get(name=label)
self.assertEqual(self.comp.description, new_computer.description)
self.assertEqual(self.comp.get_hostname(), new_computer.get_hostname())
self.assertEqual(self.comp.get_transport_type(), new_computer.get_transport_type())
self.assertEqual(self.comp.get_scheduler_type(), new_computer.get_scheduler_type())
self.assertEqual(self.comp.get_shebang(), new_computer.get_shebang())
self.assertEqual(self.comp.get_workdir(), new_computer.get_workdir())
self.assertEqual(self.comp.get_mpirun_command(), new_computer.get_mpirun_command())
self.assertEqual(self.comp.get_default_mpiprocs_per_machine(), new_computer.get_default_mpiprocs_per_machine())
self.assertEqual(self.comp.get_prepend_text(), new_computer.get_prepend_text())
self.assertEqual(self.comp.get_append_text(), new_computer.get_append_text())
self.assertEqual(self.comp.hostname, new_computer.hostname)
self.assertEqual(self.comp.transport_type, new_computer.transport_type)
self.assertEqual(self.comp.scheduler_type, new_computer.scheduler_type)
self.assertEqual(self.comp.get_property('shebang'), new_computer.get_property('shebang'))
self.assertEqual(self.comp.get_property('work_dir'), new_computer.get_property('work_dir'))
self.assertEqual(self.comp.get_property('mpirun_command'), new_computer.get_property('mpirun_command'))
self.assertEqual(self.comp.get_property('default_mpiprocs_per_machine'), new_computer.get_property('default_mpiprocs_per_machine'))
self.assertEqual(self.comp.get_property('prepend_text'), new_computer.get_property('prepend_text'))
self.assertEqual(self.comp.get_property('append_text'), new_computer.get_property('append_text'))
2 changes: 1 addition & 1 deletion aiida/backends/tests/cmdline/params/types/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_get_by_fullname(self):
"""
Verify that using the LABEL@machinename will retrieve the correct entity
"""
identifier = '{}@{}'.format(self.entity_01.label, self.computer.name) # pylint: disable=no-member
identifier = '{}@{}'.format(self.entity_01.label, self.computer.label) # pylint: disable=no-member
result = self.param_base.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_01.uuid)

Expand Down
10 changes: 5 additions & 5 deletions aiida/backends/tests/cmdline/params/types/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_get_by_label(self):
"""
Verify that using the LABEL will retrieve the correct entity
"""
identifier = '{}'.format(self.entity_01.name)
identifier = '{}'.format(self.entity_01.label)
result = self.param.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_01.uuid)

Expand All @@ -71,11 +71,11 @@ def test_ambiguous_label_pk(self):
Verify that using an ambiguous identifier gives precedence to the ID interpretation
Appending the special ambiguity breaker character will force the identifier to be treated as a LABEL
"""
identifier = '{}'.format(self.entity_02.name)
identifier = '{}'.format(self.entity_02.label)
result = self.param.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_01.uuid)

identifier = '{}{}'.format(self.entity_02.name, OrmEntityLoader.label_ambiguity_breaker)
identifier = '{}{}'.format(self.entity_02.label, OrmEntityLoader.label_ambiguity_breaker)
result = self.param.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_02.uuid)

Expand All @@ -86,10 +86,10 @@ def test_ambiguous_label_uuid(self):
Verify that using an ambiguous identifier gives precedence to the UUID interpretation
Appending the special ambiguity breaker character will force the identifier to be treated as a LABEL
"""
identifier = '{}'.format(self.entity_03.name)
identifier = '{}'.format(self.entity_03.label)
result = self.param.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_01.uuid)

identifier = '{}{}'.format(self.entity_03.name, OrmEntityLoader.label_ambiguity_breaker)
identifier = '{}{}'.format(self.entity_03.label, OrmEntityLoader.label_ambiguity_breaker)
result = self.param.convert(identifier, None, None)
self.assertEqual(result.uuid, self.entity_03.uuid)
2 changes: 1 addition & 1 deletion aiida/backends/tests/cmdline/utils/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_get_node_summary(self):
"""Test the `get_node_summary` utility."""
from aiida.cmdline.utils.common import get_node_summary

computer_label = self.computer.name # pylint: disable=no-member
computer_label = self.computer.label # pylint: disable=no-member

code = orm.Code(
input_plugin_name='arithmetic.add',
Expand Down
5 changes: 2 additions & 3 deletions aiida/backends/tests/common/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def test_serialize_computer_round_trip(self):
computer = self.computer
deserialized = serialize.deserialize(serialize.serialize(computer))

# pylint: disable=no-member
self.assertEqual(computer.uuid, deserialized.uuid)
self.assertEqual(computer.name, deserialized.name)
self.assertEqual(computer.uuid, deserialized.uuid) # pylint: disable=no-member
self.assertEqual(computer.label, deserialized.label) # pylint: disable=no-member

def test_serialize_unstored_node(self):
"""Test that you can't serialize an unstored node"""
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/engine/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def tearDown(self):

def test_get_minimum_update_interval(self):
"""Test the `JobsList.get_minimum_update_interval` method."""
minimum_poll_interval = self.auth_info.computer.get_minimum_job_poll_interval()
minimum_poll_interval = self.auth_info.computer.get_property('minimum_job_poll_interval')
self.assertEqual(self.jobs_list.get_minimum_update_interval(), minimum_poll_interval)

def test_last_updated(self):
Expand Down
6 changes: 3 additions & 3 deletions aiida/backends/tests/orm/test_querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,11 @@ def test_statistics_default_class(self):
# pylint: disable=no-member
expected_dict = {
'description': self.computer.description,
'scheduler_type': self.computer.get_scheduler_type(),
'scheduler_type': self.computer.scheduler_type,
'hostname': self.computer.hostname,
'uuid': self.computer.uuid,
'name': self.computer.name,
'transport_type': self.computer.get_transport_type(),
'name': self.computer.label,
'transport_type': self.computer.transport_type,
'id': self.computer.id,
'metadata': self.computer.get_metadata(),
}
Expand Down
Loading