Esempio n. 1
0
def test_load_invalid_report_raise_exception():
    data = {
        "last_updated": "2019-08-15T14:21:1211",  # invalid timestamp
        "last_updated_by": "pubtools.pulplib",
        "repos": {
            "repo1": {
                "message": "Maintenance Mode Enabled",
                "owner": "pubtools.pulplib",
                "started": "2019-08-15T14:21:12Z",
            }
        },
    }

    with pytest.raises(InvalidDataException):
        MaintenanceReport._from_data(data)
Esempio n. 2
0
 def get_maintenance_report(self):
     if self._maintenance_report:
         report = MaintenanceReport._from_data(
             json.loads(self._maintenance_report))
     else:
         report = MaintenanceReport()
     return f_proxy(f_return(report))
Esempio n. 3
0
def test_set_maintenance(client, requests_mocker):
    maintenance_report = {
        "last_updated": "2019-08-15T14:21:12Z",
        "last_updated_by": "pubtools.pulplib",
        "repos": {
            "repo1": {
                "message": "Maintenance Mode Enabled",
                "owner": "pubtools.pulplib",
                "started": "2019-08-15T14:21:12Z",
            }
        },
    }
    requests_mocker.post(
        "https://pulp.example.com/pulp/api/v2/repositories/search/",
        [{
            "json": [{
                "id": "redhat-maintenance",
                "notes": {
                    "_repo-type": "iso-repo"
                }
            }]
        }],
    )

    report = MaintenanceReport._from_data(maintenance_report)

    with patch("pubtools.pulplib.FileRepository.upload_file") as mocked_upload:
        with patch("pubtools.pulplib.Repository.publish") as mocked_publish:
            upload_task = Task(id="upload-task",
                               completed=True,
                               succeeded=True)
            publish_task = [
                Task(id="publish-task", completed=True, succeeded=True)
            ]

            mocked_upload.return_value = f_return(upload_task)
            mocked_publish.return_value = f_return(publish_task)

            # set_maintenance.result() should return whatever publish.result() returns
            assert client.set_maintenance(report).result() is publish_task

    # upload_file should be called with (file_obj, 'repos.json')
    args = mocked_upload.call_args
    report_file = args[0][0]
    report = MaintenanceReport()._from_data(json.loads(report_file.read()))

    assert len(report.entries) == 1
    assert report.entries[0].repo_id == "repo1"
    assert report.last_updated_by == "pubtools.pulplib"

    # search repo, upload and publish should be called once each
    assert requests_mocker.call_count == 1
    assert mocked_publish.call_count == 1
    assert mocked_upload.call_count == 1
Esempio n. 4
0
    def get_maintenance_report(self):
        self._ensure_alive()

        with self._state.lock:
            if self._state.maintenance_report:
                report = MaintenanceReport._from_data(
                    json.loads(self._state.maintenance_report)
                )
            else:
                report = MaintenanceReport()
        return f_proxy(f_return(report))
Esempio n. 5
0
def test_create_export_report():
    data = {
        "last_updated": "2019-08-15T14:21:12Z",
        "last_updated_by": "pubtools.pulplib",
        "repos": {
            "repo1": {
                "message": "Maintenance Mode Enabled",
                "owner": "pubtools.pulplib",
                "started": "2019-08-15T14:21:12Z",
            }
        },
    }

    report = MaintenanceReport._from_data(data)

    exported_data = report._export_dict()

    assert data == exported_data
Esempio n. 6
0
def test_report_add_remove():
    data = {
        "last_updated": "2019-08-15T14:21:12Z",
        "last_updated_by": "pubtools.pulplib",
        "repos": {
            "repo1": {
                "message": "Maintenance Mode Enabled",
                "owner": "pubtools.pulplib",
                "started": "2019-08-15T14:21:12Z",
            }
        },
    }

    report = MaintenanceReport._from_data(data)

    report = report.add(repo_ids=["repo2", "repo3"])

    assert len(report.entries) == 3
    assert report.last_updated_by == "ContentDelivery"

    report = report.remove(repo_ids=["repo1", "repo2"], owner="jazhang")

    assert len(report.entries) == 1
    assert report.last_updated_by == "jazhang"