test_upgrade.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import logging
  10. import pytest
  11. from materialize import buildkite
  12. from materialize.checks.actions import Action, Initialize, Manipulate, Validate
  13. from materialize.checks.all_checks import * # noqa: F401 F403
  14. from materialize.checks.all_checks.alter_connection import (
  15. AlterConnectionHost,
  16. AlterConnectionToNonSsh,
  17. AlterConnectionToSsh,
  18. )
  19. from materialize.checks.all_checks.kafka_protocols import KafkaProtocols
  20. from materialize.checks.checks import Check
  21. from materialize.checks.cloudtest_actions import (
  22. ReplaceEnvironmentdStatefulSet,
  23. SetupSshTunnels,
  24. )
  25. from materialize.checks.executors import CloudtestExecutor
  26. from materialize.checks.features import Features
  27. from materialize.checks.scenarios import Scenario
  28. from materialize.cloudtest.app.materialize_application import MaterializeApplication
  29. from materialize.cloudtest.util.wait import wait
  30. from materialize.mz_version import MzVersion
  31. from materialize.util import all_subclasses
  32. from materialize.version_list import get_previous_published_version
  33. LOGGER = logging.getLogger(__name__)
  34. class CloudtestUpgrade(Scenario):
  35. """A Platform Checks scenario that performs an upgrade in cloudtest/K8s"""
  36. def base_version(self) -> MzVersion:
  37. return get_previous_published_version(
  38. MzVersion.parse_cargo(), previous_minor=True
  39. )
  40. def actions(self) -> list[Action]:
  41. return [
  42. SetupSshTunnels(self.executor.cloudtest_application()),
  43. Initialize(self),
  44. Manipulate(self, phase=1),
  45. ReplaceEnvironmentdStatefulSet(new_tag=None),
  46. Manipulate(self, phase=2),
  47. Validate(self),
  48. ]
  49. @pytest.mark.long
  50. def test_upgrade(aws_region: str | None, log_filter: str | None, dev: bool) -> None:
  51. """Test upgrade from the last released verison to the current source by running all the Platform Checks"""
  52. last_released_version = get_previous_published_version(
  53. MzVersion.parse_cargo(), previous_minor=True
  54. )
  55. LOGGER.info(
  56. f"Testing upgrade from base version {last_released_version} to current version"
  57. )
  58. mz = MaterializeApplication(
  59. tag=str(last_released_version),
  60. aws_region=aws_region,
  61. log_filter=log_filter,
  62. release_mode=(not dev),
  63. )
  64. wait(
  65. condition="condition=Ready",
  66. resource="pod",
  67. label="cluster.environmentd.materialize.cloud/cluster-id=u1",
  68. )
  69. executor = CloudtestExecutor(application=mz, version=last_released_version)
  70. # KafkaProtocols: No shared secrets directory
  71. # AlterConnection*: No second SSH host (other_ssh_bastion) set up
  72. checks = list(
  73. all_subclasses(Check)
  74. - {
  75. KafkaProtocols,
  76. AlterConnectionToSsh,
  77. AlterConnectionToNonSsh,
  78. AlterConnectionHost,
  79. }
  80. )
  81. checks = buildkite.shard_list(checks, lambda ch: ch.__name__)
  82. if buildkite.get_parallelism_index() != 0 or buildkite.get_parallelism_count() != 1:
  83. print(
  84. f"Checks in shard with index {buildkite.get_parallelism_index()}: {[c.__name__ for c in checks]}"
  85. )
  86. scenario = CloudtestUpgrade(checks=checks, executor=executor, features=Features([]))
  87. scenario.run()