def test_missing_parameter(self, *args): with patch.dict('sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client.RestClient': self.module_mock, }): from ansible.modules.network.radware import vdirect_commit try: params = BASE_PARAMS.copy() vdirect_commit.VdirectCommit(params) self.fail("KeyError was not thrown for missing parameter") except KeyError: assert True
def test_commit(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client.RestClient': self.module_mock, }): from ansible.modules.network.radware import vdirect_commit BASE_PARAMS.update(COMMIT_PARAMS) vdirectcommit = vdirect_commit.VdirectCommit(BASE_PARAMS) vdirectcommit.client.adc = DeviceMock('adc', vdirectcommit.client) vdirectcommit.client.container = DeviceMock( 'vx', vdirectcommit.client) vdirectcommit.client.appWall = DeviceMock('appwall', vdirectcommit.client) vdirectcommit.client.defensePro = DeviceMock( 'defensepro', vdirectcommit.client) res = vdirectcommit.commit() assert res == MODULE_RESULT vdirectcommit.sync = False for detail in MODULE_RESULT['details']: if 'sync' in detail: detail['sync'] = vdirect_commit.NOT_PERFORMED res = vdirectcommit.commit() assert res == MODULE_RESULT vdirectcommit.client.adc.control_result = COMMIT_RESULT_204 vdirectcommit.client.adc.control_result[ self.module_mock.rest_client.RESP_STATUS] = 500 vdirectcommit.client.adc.control_result[ self.module_mock.rest_client.RESP_STR] = 'Some Failure' MODULE_RESULT[ 'msg'] = 'Failure occurred while performing requested actions on devices. See details' for detail in MODULE_RESULT['details']: if detail['device_name'] == 'adc': detail['apply'] = vdirect_commit.FAILED detail['failure_description'] = 'Some Failure' detail['save'] = vdirect_commit.NOT_PERFORMED detail['sync'] = vdirect_commit.NOT_PERFORMED res = vdirectcommit.commit() assert res == MODULE_RESULT vdirectcommit.client.adc.throw_exception(control_throw=True) for detail in MODULE_RESULT['details']: if detail['device_name'] == 'adc': detail['failure_description'] = 'Exception occurred while performing apply action. ' \ 'Exception: exception message' res = vdirectcommit.commit() assert res == MODULE_RESULT
def test_validate_devices(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client.RestClient': self.module_mock, }): from ansible.modules.network.radware import vdirect_commit BASE_PARAMS.update(COMMIT_PARAMS) vdirectcommit = vdirect_commit.VdirectCommit(BASE_PARAMS) vdirectcommit.client.adc = DeviceMock('adc', vdirectcommit.client) vdirectcommit.client.container = DeviceMock( 'vx', vdirectcommit.client) vdirectcommit.client.appWall = DeviceMock('appwall', vdirectcommit.client) vdirectcommit.client.defensePro = DeviceMock( 'defensepro', vdirectcommit.client) vdirectcommit._validate_devices() assert True vdirectcommit.client.adc.throw_exception(True) try: vdirectcommit._validate_devices() self.fail( "CommitException was not thrown for device communication failure" ) except vdirect_commit.CommitException: assert True vdirectcommit.client.adc.throw_exception(False) vdirectcommit.client.defensePro.throw_exception(True) try: vdirectcommit._validate_devices() self.fail( "CommitException was not thrown for device communication failure" ) except vdirect_commit.CommitException: assert True vdirectcommit.client.defensePro.throw_exception(False) vdirectcommit.client.adc.name = 'wrong' try: vdirectcommit._validate_devices() self.fail( "MissingDeviceException was not thrown for missing device") except vdirect_commit.MissingDeviceException: assert True