Beispiel #1
0
def test_get_doc_mock_deckhand(*args):
    """Get doc should return a document"""
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    dco.config = make_fake_config()
    doc = dco.get_doc(99)
    assert doc == 'abcdefg'
Beispiel #2
0
def test_get_doc_no_deckhand():
    """Get doc should fail to contact deckhand return a document"""
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    with pytest.raises(AirflowException) as expected_exc:
        dco.get_doc(99)
    assert "Failed to retrieve deployment" in str(expected_exc)
Beispiel #3
0
def test_get_revision_id(ti):
    """Test that get revision id follows desired exits"""
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    ti = airflow.models.TaskInstance(task=mock.MagicMock(),
                                     execution_date=None)
    rid = dco.get_revision_id(ti)
    assert rid == 2
Beispiel #4
0
def test_execute_no_client(*args):
    # no keystone authtoken present in configuration
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    with pytest.raises(AirflowException) as expected_exc:
        dco.execute(context={})
    assert ("Failed to retrieve deployment configuration yaml"
            ) in str(expected_exc)
Beispiel #5
0
def test_get_doc_mock_deckhand_invalid(*args):
    """Get doc should return a document"""
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")

    with pytest.raises(AirflowException) as airflow_ex:
        dco.get_doc(99)
    assert 'valid deployment-configuration' in str(airflow_ex)
Beispiel #6
0
def test_get_revision_id_none(ti):
    """Test that get revision id follows desired exits"""
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    ti = airflow.models.TaskInstance(task=mock.MagicMock(), execution_date="o")
    with pytest.raises(AirflowException) as expected_exc:
        rid = dco.get_revision_id(ti)
    assert "Design_revision is not set." in str(expected_exc)
Beispiel #7
0
def test_execute_exception():
    """Test that execute results in a failure with bad context"""

    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    with pytest.raises(AirflowException) as expected_exc:
        # Design revision is not set on xcom pull
        dco.execute(context={})
    assert ("Design_revision is not set. Cannot proceed with retrieval"
            " of the design configuration") in str(expected_exc)
Beispiel #8
0
def test_map_config_keys():
    """Should reutrn the new dict from the yaml dict"""
    yaml_dict = yaml.safe_load(sample_deployment_config)
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    mapped = dco.map_config_keys(yaml_dict)
    for key in DeploymentConfigurationOperator.config_keys_defaults:
        assert key in mapped
    assert mapped.get("physical_provisioner.deploy_interval") == 900
    assert mapped.get("physical_provisioner.verify_timeout") == 60
Beispiel #9
0
def test_execute_no_client(get_revision_id, read_config):
    # no keystone authtoken present in configuration
    dco = DeploymentConfigurationOperator(main_dag_name="main",
                                          shipyard_conf="shipyard.conf",
                                          task_id="t1")
    dco.config = make_fake_config()
    with pytest.raises(AirflowException) as expected_exc:
        dco.execute(context={'task_instance': 'asdf'})
    assert ("Failed to retrieve deployment-configuration yaml") in str(
        expected_exc)
    get_revision_id.assert_called_once_with('asdf')
    read_config.assert_called_once_with()