コード例 #1
0
    def setUp(self):
        super(TestOnyxLinkaggModule, self).setUp()
        self.mock_get_config = patch.object(onyx_linkagg.OnyxLinkAggModule,
                                            "_get_port_channels")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
        self.mock_get_version = patch.object(onyx_linkagg.OnyxLinkAggModule,
                                             "_get_os_version")
        self.get_version = self.mock_get_version.start()
    def setUp(self):
        super(TestOnyxMagpModule, self).setUp()
        self.mock_get_config = patch.object(onyx_magp.OnyxMagpModule,
                                            "_get_magp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_version = patch.object(onyx_magp.OnyxMagpModule,
                                             "_get_os_version")
        self.get_version = self.mock_get_version.start()
コード例 #3
0
    def setUp(self):
        super(TestOnyxVxlanModule, self).setUp()
        self.mock_get_vxlan_config = patch.object(onyx_vxlan.OnyxVxlanModule,
                                                  "_show_vxlan_config")
        self.get_vxlan_config = self.mock_get_vxlan_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_nve_detail = patch.object(onyx_vxlan.OnyxVxlanModule,
                                                "_show_nve_detail")
        self.get_nve_detail = self.mock_get_nve_detail.start()
    def setUp(self):
        super(TestOnyxPfcInterfaceModule, self).setUp()
        self._pfc_enabled = True
        self.mock_get_config = patch.object(
            onyx_pfc_interface.OnyxPfcInterfaceModule, "_get_pfc_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
        self.mock_get_version = patch.object(
            onyx_pfc_interface.OnyxPfcInterfaceModule, "_get_os_version")
        self.get_version = self.mock_get_version.start()
コード例 #5
0
    def setUp(self):
        super(TestOnyxOspfModule, self).setUp()
        self._ospf_exists = True
        self.mock_get_config = patch.object(onyx_ospf.OnyxOspfModule,
                                            "_get_ospf_config")
        self.get_config = self.mock_get_config.start()

        self.mock_get_interfaces_config = patch.object(
            onyx_ospf.OnyxOspfModule, "_get_ospf_interfaces_config")
        self.get_interfaces_config = self.mock_get_interfaces_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def setUp(self):
        super(TestOnyxMlagVipModule, self).setUp()
        self._mlag_enabled = True
        self.mock_show_mlag = patch.object(
            onyx_mlag_vip.OnyxMLagVipModule,
            "_show_mlag")
        self.show_mlag = self.mock_show_mlag.start()
        self.mock_show_mlag_vip = patch.object(
            onyx_mlag_vip.OnyxMLagVipModule,
            "_show_mlag_vip")
        self.show_mlag_vip = self.mock_show_mlag_vip.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
コード例 #7
0
    def test_ensure_command_called(self):
        """
        Testing that command is executed with correct args
        :return:
        """
        set_module_args({
            'operation': "Upload",
            'opsName': 'Uploading_testi',
            'DN': "PLMN-PLMN/MRBTS-746",
        })

        with patch.object(basic.AnsibleModule,
                          'run_command') as mock_run_command:
            stdout = 'configuration updated'
            stderr = ''
            return_code = 0
            mock_run_command.return_value = return_code, stdout, stderr  # successful execution

            with self.assertRaises(AnsibleExitJson) as result:
                netact_cm_command.main()
            print(result.exception.args)
            self.assertTrue(result.exception.args[0]
                            ['changed'])  # ensure result is changed

        mock_run_command.assert_called_once_with([
            '/opt/oss/bin/racclimx.sh', '-op', 'Upload', '-opsName',
            'Uploading_testi', '-DN', 'PLMN-PLMN/MRBTS-746'
        ],
                                                 check_rc=True)
コード例 #8
0
    def test_withwrongargs(self):
        """
        Testing that wrong attribute causing error
        :return:
        """
        set_module_args({
            'operation': "Upload",
            'opsName': 'Uploading_testi',
            'MR': "PLMN-PLMN/MRBTS-746",
            'abc': 'abc'
        })

        with self.assertRaises(AnsibleFailJson):
            with patch.object(basic.AnsibleModule,
                              'run_command') as mock_run_command:
                stdout = 'configuration updated'
                stderr = ''
                return_code = 0
                mock_run_command.return_value = return_code, stdout, stderr  # successful execution

                with self.assertRaises(AnsibleExitJson) as result:
                    netact_cm_command.main()
                self.assertTrue(result.exception.args[0]
                                ['changed'])  # ensure result is changed

            self.assertFalse(True)  # ensure result is changed
コード例 #9
0
    def test_ensure_backupPlanName_outputs_correctly(self):
        """
        Testing that command is executed with correct args
        :return:
        """
        set_module_args({
            'operation': "Provision",
            'opsName': 'Provision_test',
            'WS': "PLMN-PLMN/MRBTS-746",
            'createBackupPlan': "Yes",
            'backupPlanName': "backupPlanName"
        })

        with patch.object(basic.AnsibleModule,
                          'run_command') as mock_run_command:
            stdout = 'configuration updated'
            stderr = ''
            return_code = 0
            mock_run_command.return_value = return_code, stdout, stderr  # successful execution

            with self.assertRaises(AnsibleExitJson) as result:
                netact_cm_command.main()
            print(result.exception.args)
            self.assertTrue(result.exception.args[0]
                            ['changed'])  # ensure result is changed

        mock_run_command.assert_called_once_with([
            '/opt/oss/bin/racclimx.sh', '-op', 'Provision', '-opsName',
            'Provision_test', '-WS', 'PLMN-PLMN/MRBTS-746',
            '-createBackupPlan', 'true', '-backupPlanName', 'backupPlanName'
        ],
                                                 check_rc=True)
 def test_create_flexcache_time_out(self, mock_sleep):
     ''' create flexcache '''
     args = {
         'volume': 'volume_err',
         'size': '50',  # 80MB minimum
         'size_unit': 'mb',  # 80MB minimum
         'vserver': 'ansibleSVM',
         'aggr_list': 'aggr1',
         'origin_volume': 'fc_vol_origin',
         'origin_vserver': 'ansibleSVM',
         'time_out': '2'
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection(job_error='time_out')
     with patch.object(my_module,
                       'flexcache_create',
                       wraps=my_obj.flexcache_create) as mock_create:
         with pytest.raises(AnsibleFailJson) as exc:
             my_obj.apply()
         print('Create: ' + repr(exc.value))
         msg = 'Error when creating flexcache: job completion exceeded expected timer of: %s seconds' \
             % args['time_out']
         assert exc.value.args[0]['msg'] == msg
         mock_create.assert_called_with()
 def test_create_flexcache_size_error(self):
     ''' create flexcache '''
     args = {
         'volume': 'volume_err',
         'size': '50',  # 80MB minimum
         'size_unit': 'mb',  # 80MB minimum
         'vserver': 'ansibleSVM',
         'aggr_list': 'aggr1',
         'origin_volume': 'fc_vol_origin',
         'origin_vserver': 'ansibleSVM',
     }
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     error = 'Size "50MB" ("52428800B") is too small.  Minimum size is "80MB" ("83886080B"). '
     if not self.onbox:
         my_obj.server = MockONTAPConnection(job_error=error)
     with patch.object(my_module,
                       'flexcache_create',
                       wraps=my_obj.flexcache_create) as mock_create:
         with pytest.raises(AnsibleFailJson) as exc:
             my_obj.apply()
         print('Create: ' + repr(exc.value))
         msg = 'Error when creating flexcache: %s' % error
         assert exc.value.args[0]['msg'] == msg
         mock_create.assert_called_with()
 def test_delete_flexcache_exists_junctionpath_with_force(self):
     ''' delete flexcache '''
     args = {
         'volume': 'volume',
         'vserver': 'ansibleSVM',
         'junction_path': 'jpath',
         'state': 'absent',
         'force_offline': 'true',
         'force_unmount': 'true'
     }
     self.create_flexcache(args['vserver'], args['volume'],
                           args['junction_path'])
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('vserver', 'flex')
     with patch.object(my_module,
                       'flexcache_delete',
                       wraps=my_obj.flexcache_delete) as mock_delete:
         with pytest.raises(AnsibleExitJson) as exc:
             my_obj.apply()
         print('Delete: ' + repr(exc.value))
         assert exc.value.args[0]['changed']
         mock_delete.assert_called_with()
 def test_delete_flexcache_exists_junctionpath_no_force(self):
     ''' delete flexcache '''
     args = {
         'volume': 'volume',
         'vserver': 'ansibleSVM',
         'junction_path': 'jpath',
         'state': 'absent',
         'force_offline': 'true'
     }
     self.create_flexcache(args['vserver'], args['volume'],
                           args['junction_path'])
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     error = '160:Volume volume on Vserver ansibleSVM must be unmounted before being taken offline or restricted.'
     if not self.onbox:
         my_obj.server = MockONTAPConnection('vserver',
                                             'flex',
                                             api_error=error)
     with patch.object(my_module,
                       'flexcache_delete',
                       wraps=my_obj.flexcache_delete) as mock_delete:
         with pytest.raises(AnsibleFailJson) as exc:
             my_obj.apply()
         print('Delete: ' + repr(exc.value))
         msg = 'Error deleting FlexCache : NetApp API failed. Reason - %s' % error
         assert exc.value.args[0]['msg'] == msg
         mock_delete.assert_called_with()
 def test_create_flexcache_multiplier(self):
     ''' create flexcache with aggregate multiplier'''
     args = {
         'volume': 'volume',
         'size': '90',  # 80MB minimum
         'size_unit': 'mb',  # 80MB minimum
         'vserver': 'ansibleSVM',
         'aggr_list': 'aggr1',
         'origin_volume': 'fc_vol_origin',
         'origin_vserver': 'ansibleSVM',
         'aggr_list_multiplier': '2',
     }
     self.delete_flexcache(args['vserver'], args['volume'])
     args.update(self.args)
     set_module_args(args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection()
     with patch.object(my_module,
                       'flexcache_create',
                       wraps=my_obj.flexcache_create) as mock_create:
         with pytest.raises(AnsibleExitJson) as exc:
             my_obj.apply()
         print('Create: ' + repr(exc.value))
         assert exc.value.args[0]['changed']
         mock_create.assert_called_with()
def test_create_lambda_if_not_exist():

    set_module_args(base_module_args)
    (boto3_conn_double, lambda_client_double) = make_mock_no_connection_connection(code_change_lambda_config)

    with patch.object(lda, 'boto3_conn', boto3_conn_double):
        try:
            lda.main()
        except SystemExit:
            pass

    # guard against calling other than for a lambda connection (e.g. IAM)
    assert(len(boto3_conn_double.mock_calls) > 0), "boto connections never used"
    assert(len(boto3_conn_double.mock_calls) < 2), "multiple boto connections used unexpectedly"
    assert(len(lambda_client_double.update_function_configuration.mock_calls) == 0), \
        "unexpectedly updated lambda configuration when should have only created"
    assert(len(lambda_client_double.update_function_code.mock_calls) == 0), \
        "update lambda function code when function should have been created only"
    assert(len(lambda_client_double.create_function.mock_calls) > 0), \
        "failed to call create_function "
    (create_args, create_kwargs) = lambda_client_double.create_function.call_args
    assert (len(create_kwargs) > 0), "expected create called with keyword args, none found"

    try:
        # For now I assume that we should NOT send an empty environment.  It might
        # be okay / better to explicitly send an empty environment.  However `None'
        # is not acceptable - mikedlr
        create_kwargs["Environment"]
        raise(Exception("Environment sent to boto when none expected"))
    except KeyError:
        pass  # We are happy, no environment is fine
 def setUp(self):
     """Setup."""
     super(TestIcinga2Feature, self).setUp()
     self.module = icinga2_feature
     self.mock_get_bin_path = patch.object(basic.AnsibleModule, 'get_bin_path', get_bin_path)
     self.mock_get_bin_path.start()
     self.addCleanup(self.mock_get_bin_path.stop)  # ensure that the patching is 'undone'
コード例 #17
0
 def __getResult(self, cmd_fun):
     with patch.object(basic.AnsibleModule,
                       'run_command') as mock_run_command:
         mock_run_command.side_effect = cmd_fun
         with self.assertRaises(AnsibleExitJson) as result:
             module.main()
     return result
    def test_successful_message_with_notify(self):
        """Test failure message"""
        set_module_args({
            'subscription': 'test',
            'token': 'abc',
            'room': 'test',
            'msg': 'test',
            'notify': 'bell'
        })

        with patch.object(campfire, "fetch_url") as fetch_url_mock:
            fetch_url_mock.return_value = (None, {"status": 200})
            with self.assertRaises(AnsibleExitJson):
                self.module.main()

            assert fetch_url_mock.call_count == 2
            notify_call = fetch_url_mock.mock_calls[0]
            url = notify_call[1][1]
            data = notify_call[2]['data']

            assert url == 'https://test.campfirenow.com/room/test/speak.xml'
            assert data == '<message><type>SoundMessage</type><body>bell</body></message>'

            message_call = fetch_url_mock.mock_calls[1]
            url = message_call[1][1]
            data = message_call[2]['data']

            assert url == 'https://test.campfirenow.com/room/test/speak.xml'
            assert data == '<message><body>test</body></message>'
    def setUp(self):
        super(TestOnyxTrafficClassModule, self).setUp()
        self.mock_get_congestion_control_config = patch.object(
            onyx_traffic_class.OnyxTrafficClassModule,
            "_show_interface_congestion_control")
        self.get_congestion_control_config = self.mock_get_congestion_control_config.start(
        )

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_get_dcb_config = patch.object(
            onyx_traffic_class.OnyxTrafficClassModule,
            "_show_interface_dcb_ets")
        self.get_dcb_config = self.mock_get_dcb_config.start()
    def setUp(self):
        super(TestOnyxQosModule, self).setUp()
        self.mock_get_if_qos_config = patch.object(onyx_qos.OnyxQosModule,
                                                   "_show_interface_qos")
        self.get_if_qos_config = self.mock_get_if_qos_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def setUp(self):
        super(TestOnyxBufferPoolModule, self).setUp()
        self.mock_get_buffer_pool_config = patch.object(
            onyx_buffer_pool.OnyxBufferPoolModule, "_show_traffic_pool")
        self.get_buffer_pool_config = self.mock_get_buffer_pool_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def setUp(self):
        super(TestOnyxLldpInterfaceModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_lldp_interface.OnyxLldpInterfaceModule, "_get_lldp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
コード例 #23
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxIgmpModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_igmp.OnyxIgmpModule, "_show_igmp")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
コード例 #24
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxNtpServersPeersModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_ntp_servers_peers.OnyxNTPServersPeersModule, "_show_peers_servers_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
def test_lookup_multiple_obj(dummy_credentials):
    avi_lookup = lookup_loader.get('avi')
    avi_mock = MagicMock()
    avi_mock.return_value.get.return_value.json.return_value = data[
        "mock_multiple_obj"]
    with patch.object(avi, 'ApiSession', avi_mock):
        retval = avi_lookup.run([], {},
                                avi_credentials=dummy_credentials,
                                obj_type="network")
        assert retval == data["mock_multiple_obj"]["results"]
コード例 #26
0
    def setUp(self):
        super(TestOnyxMlagIplModule, self).setUp()
        self._mlag_enabled = True
        self.mock_get_config = patch.object(onyx_mlag_ipl.OnyxMlagIplModule,
                                            "_show_mlag_data")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
def test_lookup_single_obj(dummy_credentials):
    avi_lookup = lookup_loader.get('avi')
    avi_mock = MagicMock()
    avi_mock.return_value.get_object_by_name.return_value = data[
        "mock_single_obj"]
    with patch.object(avi, 'ApiSession', avi_mock):
        retval = avi_lookup.run([], {},
                                avi_credentials=dummy_credentials,
                                obj_type="network",
                                obj_name='PG-123')
        assert retval[0] == data["mock_single_obj"]
    def test_dont_update_same_value(self, *args):
        with patch.object(self.module,
                          'delete_deploy_key') as delete_deploy_key_mock:
            with patch.object(self.module,
                              'create_deploy_key') as create_deploy_key_mock:
                with self.assertRaises(AnsibleExitJson) as exec_info:
                    set_module_args({
                        'client_id': 'ABC',
                        'client_secret': 'XXX',
                        'username': '******',
                        'repository': 'repo',
                        'key': 'new public key',
                        'label': 'mykey',
                        'state': 'present',
                    })
                    self.module.main()

                self.assertEqual(delete_deploy_key_mock.call_count, 0)
                self.assertEqual(create_deploy_key_mock.call_count, 0)
                self.assertEqual(exec_info.exception.args[0]['changed'], False)
    def setUp(self):
        self.enabled = False
        super(TestOnyxSyslogFilesModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_syslog_files.OnyxSyslogFilesModule, "show_logging")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.notmintest.not_a_real_collection.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def test_failed_message(self):
        """tests failing to send a message"""

        set_module_args({'token': 'XXXX/YYYY/ZZZZ', 'msg': 'test'})

        with patch.object(slack, "fetch_url") as fetch_url_mock:
            fetch_url_mock.return_value = (None, {
                "status": 404,
                'msg': 'test'
            })
            with self.assertRaises(AnsibleFailJson):
                self.module.main()