def test_get_successes_for_task(self): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.get_task_dict = _fake_get_task_dict s = op.get_successes_for_task('0') for i in range(1, 3): assert "node{}".format(i) in s
def test_do_execute_with_dgm(self, nl, caplog): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op.design_ref = {"a": "b"} op.do_execute() assert "critical groups have met their success criteria" in caplog.text
def test_get_successess_for_task_more_logging(self): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.get_task_dict = _fake_get_task_dict s = op._get_successes_for_task('99') for i in range(97, 98): assert "node{}".format(i) in s assert "node2" not in s
def test_execute_prepare(self): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op._setup_configured_values() op._execute_task = mock.MagicMock(return_value=TASK_RESULT) group = DeploymentGroup(GROUP_DICT, mock.MagicMock()) group.actionable_nodes = ['node1', 'node2', 'node3'] op._execute_prepare(group) assert op._execute_task.call_count == 1
def get_deployment_strategy(self, udoc): """Assert that the base class method get_unique_doc would be invoked """ op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op.dc['physical_provisioner.deployment_strategy'] = 'taco-salad' op.setup_deployment_strategy() udoc.assert_called_once_with(name='taco-salad', schema="shipyard/DeploymentStrategy/v1")
def test_do_execute_with_dgm(self, nl, caplog): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op.design_ref = {"a": "b"} op.notes_helper = get_notes_helper() op.action_id = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" op.task_id = "prepare_and_deploy_nodes" op.do_execute() assert "critical groups have met their success criteria" in caplog.text
def test_do_execute_exception(self, nl, pdg, get_dgm): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") with pytest.raises(AirflowException): op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op.design_ref = {} op.do_execute() get_dgm.assert_called_once() nl.assert_called_once() pdg.assert_called_once()
def test_execute_deployment_k8s_fail(self, cns, caplog): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op._setup_configured_values() op._execute_task = mock.MagicMock(return_value=TASK_RESULT) op.join_wait = 0 group = DeploymentGroup(GROUP_DICT, mock.MagicMock()) group.actionable_nodes = ['node1', 'node2', 'node3'] task_res = op._execute_deployment(group) op._execute_task.assert_called_once() cns.assert_called_once() assert 'node4 failed to join Kubernetes' in caplog.text assert len(task_res.successes) == 2
def test_do_execute_exception(self, nl, pdg, get_dgm): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") with pytest.raises(AirflowException): op.dc = copy.deepcopy( DeploymentConfigurationOperator.config_keys_defaults) op.design_ref = {} op.notes_helper = get_notes_helper() op.action_id = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" op.task_id = "prepare_and_deploy_nodes" op.do_execute() assert get_dgm.call_count == 1 assert nl.call_count == 1 assert pdg.call_count == 1
def test_init_DrydockNodesOperator(self): op = DrydockNodesOperator(main_dag_name="main", shipyard_conf=CONF_FILE, task_id="t1") assert op is not None