Ejemplo n.º 1
0
 def test_all_selector_group(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_ALL_SELECTOR),
                          node_lookup)
     assert dg.selectors[0].all_selector
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_ALL_SELECTOR_2),
                          node_lookup)
     assert dg.selectors[0].all_selector
Ejemplo n.º 2
0
 def test_set_stage(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_ALL_SELECTOR),
                          node_lookup)
     with pytest.raises(DeploymentGroupStageError):
         dg.stage = Stage.DEPLOYED
     dg.stage = Stage.PREPARED
     assert dg.stage == Stage.PREPARED
     dg.stage = Stage.DEPLOYED
     assert dg.stage == Stage.DEPLOYED
Ejemplo n.º 3
0
    def test_handle_broken_node_lookup(self):
        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as err:
            dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_1),
                                 broken_node_lookup_1)
        assert str(err).endswith("iterable")

        with pytest.raises(InvalidDeploymentGroupNodeLookupError) as err:
            dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_1),
                                 broken_node_lookup_2)
        assert str(err).endswith("but not all strings")
 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
Ejemplo n.º 5
0
 def test_succ_criteria_failure(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_MULTI_SELECTOR),
                          node_lookup)
     assert set(dg.full_nodes) == {'node7', 'node8', 'node9', 'node11'}
     failed = dg.get_failed_success_criteria(
         success_node_list=['node8', 'node11', 'node9'])
     assert len(failed) == 1
     assert failed[0] == {
         'actual': 75.0,
         'criteria': 'percent_successful_nodes',
         'needed': 79
     }
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def test_basic_class_multi_selector(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_MULTI_SELECTOR),
                          node_lookup)
     assert set(dg.full_nodes) == {'node7', 'node8', 'node9', 'node11'}
     assert dg.selectors[0].get_node_labels_as_dict() == {}
     assert dg.selectors[1].get_node_labels_as_dict() == {
         'label1': 'label1'
     }
Ejemplo n.º 8
0
 def test_basic_class(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_1), node_lookup)
     assert set(dg.full_nodes) == {'node8'}
     assert dg.critical
     assert dg.name == "control-nodes"
     assert set(dg.depends_on) == {"ntp-node"}
     assert len(dg.selectors) == 1
     assert not dg.success_criteria._always_succeed
     assert dg.success_criteria.pct_succ_nodes == 90
     assert dg.success_criteria.min_succ_nodes == 3
     assert dg.success_criteria.max_failed_nodes == 1
     assert dg.stage == Stage.NOT_STARTED
Ejemplo n.º 9
0
 def test_handle_none_node_lookup(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_1), crummy_node_lookup)
     assert dg.full_nodes == []
Ejemplo n.º 10
0
 def test_selector_excludes_all(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_EXCLUDES_ALL),
                          node_lookup)
     assert dg.full_nodes == []
Ejemplo n.º 11
0
 def test_succ_criteria_minimal_criteria(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_MINIMAL_SUCC_CRITERIA),
                          node_lookup)
     assert set(dg.full_nodes) == {'node7', 'node8', 'node9', 'node11'}
     assert not dg.get_failed_success_criteria(
         success_node_list=['node8', 'node11', 'node9'])
Ejemplo n.º 12
0
 def test_succ_criteria_success(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_MULTI_SELECTOR),
                          node_lookup)
     assert set(dg.full_nodes) == {'node7', 'node8', 'node9', 'node11'}
     assert not dg.get_failed_success_criteria(
         success_node_list=['node7', 'node8', 'node11', 'node9'])
Ejemplo n.º 13
0
 def test_basic_class_no_succ_criteria(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_NO_SUCC_CRITERIA),
                          node_lookup)
     assert dg.success_criteria._always_succeed
     assert not dg.get_failed_success_criteria([])
Ejemplo n.º 14
0
 def test_basic_class_missing_req(self):
     with pytest.raises(InvalidDeploymentGroupError):
         DeploymentGroup(yaml.safe_load(_GROUP_YAML_MISSING), node_lookup)
Ejemplo n.º 15
0
 def test_basic_class_multi_selector(self):
     dg = DeploymentGroup(yaml.safe_load(_GROUP_YAML_MULTI_SELECTOR),
                          node_lookup)
     assert set(dg.full_nodes) == {'node7', 'node8', 'node9', 'node11'}