def test_handle_multiple_directives(self): """Handle multiple Livepatch directives using livepatch config.""" cfg = { "entitlement": { "directives": { "remoteServer": "value1", "caCerts": "value2", "ignored": "ignoredvalue", } } } with mock.patch("uaclient.util.subp") as m_subp: process_config_directives(cfg) expected_calls = [ mock.call( ["/snap/bin/canonical-livepatch", "config", "ca-certs=value2"], capture=True, ), mock.call( [ "/snap/bin/canonical-livepatch", "config", "remote-server=value1", ], capture=True, ), ] assert expected_calls == m_subp.call_args_list
def test_call_livepatch_config_command(self, directive_key, livepatch_param_tmpl): """Livepatch config directives are passed to livepatch config.""" directive_value = '%s-value' % directive_key cfg = {'entitlement': {'directives': {directive_key: directive_value}}} with mock.patch('uaclient.util.subp') as m_subp: process_config_directives(cfg) expected_subp = mock.call([ '/snap/bin/canonical-livepatch', 'config', livepatch_param_tmpl % directive_value ], capture=True) assert [expected_subp] == m_subp.call_args_list
def test_call_livepatch_config_command(self, directive_key, livepatch_param_tmpl): """Livepatch config directives are passed to livepatch config.""" directive_value = "{}-value".format(directive_key) cfg = {"entitlement": {"directives": {directive_key: directive_value}}} with mock.patch("uaclient.util.subp") as m_subp: process_config_directives(cfg) expected_subp = mock.call( [ "/snap/bin/canonical-livepatch", "config", livepatch_param_tmpl.format(directive_value), ], capture=True, ) assert [expected_subp] == m_subp.call_args_list
def test_handle_multiple_directives(self): """Handle multiple Livepatch directives using livepatch config.""" cfg = { 'entitlement': { 'directives': { 'remoteServer': 'value1', 'caCerts': 'value2', 'ignored': 'ignoredvalue' } } } with mock.patch('uaclient.util.subp') as m_subp: process_config_directives(cfg) expected_calls = [ mock.call( ['/snap/bin/canonical-livepatch', 'config', 'ca-certs=value2'], capture=True), mock.call([ '/snap/bin/canonical-livepatch', 'config', 'remote-server=value1' ], capture=True) ] assert expected_calls == m_subp.call_args_list
def test_ignores_other_or_absent(self, directives): """Ignore empty or unexpected directives and do not call livepatch.""" cfg = {'entitlement': {'directives': directives}} with mock.patch('uaclient.util.subp') as m_subp: process_config_directives(cfg) assert 0 == m_subp.call_count