Skip to content

Commit

Permalink
Automate adding manifest to integTest notification cron (#5098)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Oct 11, 2024
1 parent 838e472 commit ec34a44
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/manifests_workflow/input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def jenkins_path(self) -> str:
def cron_jenkinsfile(self) -> str:
return os.path.join(self.jenkins_path(), "check-for-build.jenkinsfile")

@classmethod
def cron_integTest_notification_jenkinsfile(self) -> str:
return os.path.join(self.jenkins_path(), "integ-test-notification.jenkinsfile")

@classmethod
def os_versionincrement_workflow(self) -> str:
return os.path.join(self.workflows_path(), "os-increment-plugin-versions.yml")
Expand Down Expand Up @@ -120,6 +124,7 @@ def update(
for new_version_entry in new_versions:
self.write_manifest(new_version_entry, branch_versions[new_version_entry], known_versions)
self.add_to_cron(new_version_entry)
self.add_to_integTest_notification_cron(new_version_entry)
self.add_to_versionincrement_workflow(new_version_entry)
known_versions.append(new_version_entry)

Expand Down Expand Up @@ -212,6 +217,24 @@ def add_to_cron(self, version: str) -> None:

logging.info(f"Wrote {jenkinsfile}")

def add_to_integTest_notification_cron(self, version: str) -> None:
logging.info(f"Adding new version to integ test notification cron: {version}")
integTestJenkinsfile = self.cron_integTest_notification_jenkinsfile()
with open(integTestJenkinsfile, "r") as f:
data = f.read()

cron_entry = f"H */6 * * * %INPUT_MANIFEST={version}/{self.prefix}-{version}.yml\n"

if cron_entry in data:
raise ValueError(f"{integTestJenkinsfile} already contains an entry for {self.prefix} {version}")

data = data.replace("parameterizedCron('''\n", f"parameterizedCron('''\n{' ' * 12}{cron_entry}")

with open(integTestJenkinsfile, "w") as f:
f.write(data)

logging.info(f"Wrote {integTestJenkinsfile}")

def add_to_versionincrement_workflow(self, version: str) -> None:
versionincrement_workflow_files = [self.os_versionincrement_workflow(), self.osd_versionincrement_workflow()]
yaml = ruamel.yaml.YAML()
Expand Down
17 changes: 17 additions & 0 deletions tests/tests_manifests_workflow/test_input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ def test_cron_jenkinsfile(self) -> None:
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "jenkins", "check-for-build.jenkinsfile"))
)

def test_cron_integTest_notification_jenkinsfilee(self) -> None:
self.assertEqual(
InputManifests.cron_integTest_notification_jenkinsfile(),
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "jenkins", "integ-test-notification.jenkinsfile"))
)

@patch("builtins.open", new_callable=mock_open)
def test_add_to_cron(self, mock_open: MagicMock) -> None:
mock_open().read.return_value = "parameterizedCron '''\n"
Expand All @@ -226,6 +232,17 @@ def test_add_to_cron(self, mock_open: MagicMock) -> None:
"TEST_MANIFEST=0.1.2/test-0.1.2-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar\n"
)

@patch("builtins.open", new_callable=mock_open)
def test_add_to_integTest_notification_cron(self, mock_open: MagicMock) -> None:
mock_open().read.return_value = "parameterizedCron('''\n"
input_manifests = InputManifests("test")
input_manifests.add_to_integTest_notification_cron('0.1.2')
mock_open.assert_has_calls([call(InputManifests.cron_integTest_notification_jenkinsfile(), 'w')])
mock_open.assert_has_calls([call(InputManifests.cron_integTest_notification_jenkinsfile(), 'r')])
mock_open().write.assert_called_once_with(
"parameterizedCron('''\n H */6 * * * %INPUT_MANIFEST=0.1.2/test-0.1.2.yml\n"
)

def test_os_versionincrement_workflow(self) -> None:
self.assertEqual(
InputManifests.os_versionincrement_workflow(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def test_files(self) -> None:
@patch("os.chdir")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_versionincrement_workflow")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_cron")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_integTest_notification_cron")
@patch("manifests.manifest.Manifest.to_file")
@patch("manifests_workflow.input_manifests_opensearch.ComponentOpenSearchMin")
def test_update(self, mock_component_opensearch_min: MagicMock, mock_manifest_to_file: MagicMock,
def test_update(self, mock_component_opensearch_min: MagicMock, mock_manifest_to_file: MagicMock, mock_add_to_integTest_notification_cron: MagicMock,
mock_add_to_cron: MagicMock, mock_add_to_versionincrement_workflow: MagicMock,
*mocks: MagicMock) -> None:
mock_component_opensearch_min.return_value = MagicMock(name="OpenSearch")
Expand All @@ -53,6 +54,9 @@ def test_update(self, mock_component_opensearch_min: MagicMock, mock_manifest_to
)
]
mock_manifest_to_file.assert_has_calls(calls)
mock_add_to_integTest_notification_cron.assert_has_calls([
call('2.1000.1000'),
])
mock_add_to_cron.assert_has_calls([
call('2.1000.1000'),
])
Expand All @@ -62,9 +66,10 @@ def test_update(self, mock_component_opensearch_min: MagicMock, mock_manifest_to

@patch("manifests_workflow.input_manifests.InputManifests.add_to_versionincrement_workflow")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_cron")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_integTest_notification_cron")
@patch("manifests.manifest.Manifest.to_file")
@patch("manifests_workflow.input_manifests_opensearch.ComponentOpenSearchMin")
def test_update_outdated_branch(self, mock_component_opensearch_min: MagicMock, mock_manifest_to_file: MagicMock,
def test_update_outdated_branch(self, mock_component_opensearch_min: MagicMock, mock_manifest_to_file: MagicMock, mock_add_to_integTest_notification_cron: MagicMock,
mock_add_to_cron: MagicMock, mock_add_to_versionincrement_workflow: MagicMock) -> None:
mock_component_opensearch_min.return_value = MagicMock(name="OpenSearch")
mock_component_opensearch_min.branches.return_value = ["1.2"]
Expand All @@ -73,4 +78,5 @@ def test_update_outdated_branch(self, mock_component_opensearch_min: MagicMock,
manifests.update()
self.assertEqual(mock_manifest_to_file.call_count, 0)
self.assertEqual(mock_add_to_cron.call_count, 0)
self.assertEqual(mock_add_to_integTest_notification_cron.call_count, 0)
self.assertEqual(mock_add_to_versionincrement_workflow.call_count, 0)
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def test_files(self) -> None:
@patch("os.chdir")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_versionincrement_workflow")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_cron")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_integTest_notification_cron")
@patch("manifests.manifest.Manifest.to_file")
@patch("manifests_workflow.input_manifests_opensearch_dashboards.ComponentOpenSearchDashboardsMin")
def test_update(self, mock_component_opensearch_dashboards_min: MagicMock, mock_manifest_to_file: MagicMock,
def test_update(self, mock_component_opensearch_dashboards_min: MagicMock, mock_manifest_to_file: MagicMock, mock_add_to_integTest_notification_cron: MagicMock,
mock_add_to_cron: MagicMock, mock_add_to_versionincrement_workflow: MagicMock,
mock_os_chdir: MagicMock, mock_os_makedirs: MagicMock) -> None:
mock_component_opensearch_dashboards_min.return_value = MagicMock(name="OpenSearch-Dashboards")
Expand All @@ -57,15 +58,19 @@ def test_update(self, mock_component_opensearch_dashboards_min: MagicMock, mock_
mock_add_to_cron.assert_has_calls([
call('2.1000.1000')
])
mock_add_to_integTest_notification_cron.assert_has_calls([
call('2.1000.1000')
])
mock_add_to_versionincrement_workflow.assert_has_calls([
call('2.1000.1000')
])

@patch("manifests_workflow.input_manifests.InputManifests.add_to_versionincrement_workflow")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_cron")
@patch("manifests_workflow.input_manifests.InputManifests.add_to_integTest_notification_cron")
@patch("manifests.manifest.Manifest.to_file")
@patch("manifests_workflow.input_manifests_opensearch_dashboards.ComponentOpenSearchDashboardsMin")
def test_update_outdated_branch(self, mock_component_opensearch_dashboards_min: MagicMock, mock_manifest_to_file: MagicMock,
def test_update_outdated_branch(self, mock_component_opensearch_dashboards_min: MagicMock, mock_manifest_to_file: MagicMock, mock_add_to_integTest_notification_cron: MagicMock,
mock_add_to_cron: MagicMock, mock_add_to_versionincrement_workflow: MagicMock) -> None:
mock_component_opensearch_dashboards_min.return_value = MagicMock(name="OpenSearch-Dashboards")
mock_component_opensearch_dashboards_min.branches.return_value = ["1.2"]
Expand All @@ -75,4 +80,5 @@ def test_update_outdated_branch(self, mock_component_opensearch_dashboards_min:
manifests.update()
self.assertEqual(mock_manifest_to_file.call_count, 0)
self.assertEqual(mock_add_to_cron.call_count, 0)
self.assertEqual(mock_add_to_integTest_notification_cron.call_count, 0)
self.assertEqual(mock_add_to_versionincrement_workflow.call_count, 0)

0 comments on commit ec34a44

Please sign in to comment.