def test_deprecated_all(self): ''' deprecated with all options ''' args = dict(self.DEPRECATED_ARGS) # deep copy as other tests can modify args set_module_args(args) with pytest.raises(AnsibleFailJson) as exc: my_module() msg = 'Please use the new bond_1g and bond_10g options to configure the bond interfaces.' assert msg in exc.value.args[0]['msg'] msg = 'This module cannot set or change "method"' assert msg in exc.value.args[0]['msg']
def test_deprecated_10g_only(self): ''' deprecated with 10g options only ''' args = dict(self.DEPRECATED_ARGS) # deep copy as other tests can modify args for key in list(args): if '1g' in key: del args[key] set_module_args(args) with pytest.raises(AnsibleFailJson) as exc: my_module() msg = 'Please use the new bond_10g option to configure the bond 10G interface.' assert msg in exc.value.args[0]['msg'] msg = 'This module cannot set or change "method"' assert msg in exc.value.args[0]['msg']
def test_modify_all(self, mock_create_sf_connection): ''' modify with all options ''' args = dict(self.ARGS) # deep copy as other tests can modify args set_module_args(args) # my_obj.sfe will be assigned a MockSFConnection object: mock_create_sf_connection.return_value = MockSFConnection() my_obj = my_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print(exc.value.args[0]) assert exc.value.args[0]['changed'] assert 'Bond1G' in my_obj.sfe.set_network_config_args
def test_create_nothing(self, mock_create_sf_connection): ''' create without 1g or 10g options ''' args = dict(self.ARGS) # deep copy as other tests can modify args for key in list(args): if '1g' in key or '10g' in key: del args[key] set_module_args(args) # my_obj.sfe will be assigned a MockSFConnection object: mock_create_sf_connection.return_value = MockSFConnection() my_obj = my_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print(exc.value.args[0]) assert not exc.value.args[0]['changed'] assert len(my_obj.sfe.set_network_config_args) == 0
def test_create_10g_only(self, mock_create_sf_connection): ''' create with 10g options only ''' args = dict(self.ARGS) # deep copy as other tests can modify args for key in list(args): if '1g' in key: del args[key] set_module_args(args) # my_obj.sfe will be assigned a MockSFConnection object: mock_create_sf_connection.return_value = MockSFConnection() my_obj = my_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print(exc.value.args[0]) assert exc.value.args[0]['changed'] assert 'Bond1G' not in my_obj.sfe.set_network_config_args for key, attr in MAPPING_10G: assert my_obj.sfe.set_network_config_args['Bond10G'][attr] == args[key]
def test_modify_1g_only(self, mock_create_sf_connection): ''' modify with 1g options only ''' args = dict(self.ARGS) # deep copy as other tests can modify args for key in list(args): if '10g' in key: del args[key] set_module_args(args) # my_obj.sfe will be assigned a MockSFConnection object: mock_create_sf_connection.return_value = MockSFConnection() my_obj = my_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print(exc.value.args[0]) assert exc.value.args[0]['changed'] assert 'Bond1G' in my_obj.sfe.set_network_config_args assert 'Bond10G' not in my_obj.sfe.set_network_config_args print(my_obj.sfe.set_network_config_args['Bond1G']) for key in args['bond_1g']: if key != 'bond_lacp_rate': assert my_obj.sfe.set_network_config_args['Bond1G'][mapkey(key)] == args['bond_1g'][key]
def test_create_10g_only_with_default(self, mock_create_sf_connection): ''' create with 10g options only ''' args = dict(self.ARGS) # deep copy as other tests can modify args for key in list(args): if '1g' in key: del args[key] for key in DEFAULT_KEYS_10G: del args[key] set_module_args(args) # my_obj.sfe will be assigned a MockSFConnection object: mock_create_sf_connection.return_value = MockSFConnection() my_obj = my_module() with pytest.raises(AnsibleExitJson) as exc: my_obj.apply() print(exc.value.args[0]) assert exc.value.args[0]['changed'] assert 'Bond1G' not in my_obj.sfe.set_network_config_args for attr, value in DEFAULT_ATTRS.items(): if attr == 'bond-lacp_rate': # not set with ActivePassive continue assert my_obj.sfe.set_network_config_args['Bond10G'][attr] == value
def test_module_fail_when_required_args_missing(self): ''' required arguments are reported as errors ''' with pytest.raises(AnsibleFailJson) as exc: set_module_args({}) my_module() print('Info: %s' % exc.value.args[0]['msg'])