

def test_random_scheduling(self):
    random_patch = mock.patch('random.choice')
    random_mock = random_patch.start()

    def side_effect(seq):
        return seq[0]
    random_mock.side_effect = side_effect
    self._setup_cfg_agents(True, True)
    with self.hosting_device_template(host_category=self.host_category) as hosting_device_template:
        hdt = hosting_device_template['hosting_device_template']
        with self.hosting_device(template_id=hdt['id']) as hosting_device_1:
            hd1 = hosting_device_1['hosting_device']
            agents = self.plugin.get_cfg_agents_for_hosting_devices(self.adminContext, [hd1['id']], schedule=True)
            self.assertEqual(1, len(agents))
            self.assertEqual(1, random_mock.call_count)
            with self.hosting_device(template_id=hdt['id']) as hosting_device_2:
                hd2 = hosting_device_2['hosting_device']
                self.plugin.get_cfg_agents_for_hosting_devices(self.adminContext, [hd2['id']], schedule=True)
                self.assertEqual(2, random_mock.call_count)

dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/tests/unit/cisco/device_manager/test_hosting_device_cfg_agent_scheduler.py HostingDeviceToCfgAgentRandomSchedulerTestCase.test_random_scheduling/original