def test_scale_vmirs_same_replica_number(self, mock_crd_get,
                                          mock_crd_patch, mock_client):
     mock_client.return_value = dict()
     mock_crd_get.return_value = dict(spec=dict(replicas=2))
     with pytest.raises(AnsibleExitJson) as result:
         mymodule.KubeVirtScaleVMIRS().execute_module()
     assert not result.value[0]['changed']
 def test_scale_vmirs_main(self, mock_crd_get, mock_crd_patch, mock_client):
     mock_client.return_value = dict()
     mock_crd_get.return_value = dict(spec=dict(replicas=1))
     mock_crd_patch.return_value = dict()
     with pytest.raises(AnsibleExitJson) as result:
         mymodule.KubeVirtScaleVMIRS().execute_module()
     assert result.value[0]['changed']
     mock_crd_patch.assert_called_once_with(
         'kubevirt.io', 'v1alpha2', 'vms',
         'virtualmachineinstancereplicasets', 'freyja',
         dict(spec=dict(replicas=2)))
コード例 #3
0
    def test_stream_creation(self, mock_watch):
        _name = 'test-vmirs'
        # Desired state:
        args = dict(name=_name, namespace='vms', replicas=2, wait=True)
        set_module_args(args)

        # Mock pre-change state:
        resource_args = dict( kind='VirtualMachineInstanceReplicaSet', **RESOURCE_DEFAULT_ARGS )
        K8sAnsibleMixin.find_resource.return_value = Resource(**resource_args)
        res_inst = ResourceInstance('', dict(metadata = {'name': _name}, spec = {'replicas': 3}))
        Resource.get.return_value = res_inst

        # Actual test:
        mock_watch.side_effect = KubernetesException("Test", value=42)
        with pytest.raises(AnsibleFailJson) as result:
            mymodule.KubeVirtScaleVMIRS().execute_module()
コード例 #4
0
    def test_scale_vmirs_nowait(self, _replicas, _changed):
        _name = 'test-vmirs'
        # Desired state:
        args = dict(name=_name, namespace='vms', replicas=2, wait=False)
        set_module_args(args)

        # Mock pre-change state:
        resource_args = dict( kind='VirtualMachineInstanceReplicaSet', **RESOURCE_DEFAULT_ARGS )
        K8sAnsibleMixin.find_resource.return_value = Resource(**resource_args)
        res_inst = ResourceInstance('', dict(metadata = {'name': _name}, spec = {'replicas': _replicas}))
        Resource.get.return_value = res_inst

        # Actual test:
        with pytest.raises(AnsibleExitJson) as result:
            mymodule.KubeVirtScaleVMIRS().execute_module()
        assert result.value[0]['changed'] == _changed
コード例 #5
0
    def test_scale_vmirs_wait(self, mock_create_stream, _replicas, _changed):
        _name = 'test-vmirs'
        # Desired state:
        args = dict(name=_name, namespace='vms', replicas=_replicas, wait=True)
        set_module_args(args)

        # Mock pre-change state:
        resource_args = dict( kind='VirtualMachineInstanceReplicaSet', **RESOURCE_DEFAULT_ARGS )
        K8sAnsibleMixin.find_resource.return_value = Resource(**resource_args)
        res_inst = ResourceInstance('', dict(metadata = {'name': _name}, spec = {'replicas': 2}))
        Resource.get.return_value = res_inst

        # Mock post-change state:
        stream_obj = dict(
            status = dict(readyReplicas=_replicas),
            metadata = dict(name = _name)
            )
        mock_watcher = MagicMock()
        mock_create_stream.return_value = ( mock_watcher, [ dict(object=stream_obj) ] )

        # Actual test:
        with pytest.raises(AnsibleExitJson) as result:
            mymodule.KubeVirtScaleVMIRS().execute_module()
        assert result.value[0]['changed'] == _changed