Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions client/src/cbltest/greenboarduploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
from pydantic import BaseModel, ConfigDict, Field

from cbltest.api.syncgateway import CouchbaseVersion
from cbltest.logging import cbl_info, cbl_warning


class IntegrationTestRun(BaseModel):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly the name I'd choose. We don't refer to these as integration tests anywhere. If anything they are E2ETestRuns or TestRunResult, or something.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wanted to pick a name that didn't start with Test because that gets picked up as a test class by discovery.

"""
Store the information for a test run in greenboard
"""

model_config = ConfigDict(populate_by_name=True)

build: int # build number of CBL build
version: str # major.minor.patch version of CBL
sgw_version: str = Field(alias="sgwVersion") # Sync Gateway version, optional
fail_count: int = Field(alias="failCount") # number of failing tests
pass_count: int = Field(alias="passCount") # number of passing tests
platform: str # CBL platform
os: str # Operating system for CBL


class GreenboardUploader:
"""
A class for uploading results to a specified greenboard server bucket.
Expand Down Expand Up @@ -122,15 +139,15 @@ def upload(
cbl_warning(f"Could not parse build number from '{version}'")

self._upload_document(
{
"build": parsed_build,
"version": parsed_version,
"sgwVersion": sgw_version_str,
"failCount": self.__fail_count,
"passCount": self.__pass_count,
"platform": platform,
"os": os_name,
}
IntegrationTestRun(
build=parsed_build,
version=parsed_version,
sgwVersion=sgw_version_str,
failCount=self.__fail_count,
passCount=self.__pass_count,
platform=platform,
os=os_name,
)
)

def record_upgrade_step(
Expand Down Expand Up @@ -288,7 +305,7 @@ def upload_upgrade_batch(self, results_file: str) -> None:
# `build` fields preserve what was actually running at each step.
target_build = 0

self._upload_document(
self._upsert(
{
"build": target_build,
"version": target_version,
Expand All @@ -306,8 +323,11 @@ def upload_upgrade_batch(self, results_file: str) -> None:
f"failedAt={failed_at}"
)

def _upload_document(self, doc: dict) -> None:
"""Upload a document to the greenboard bucket with common fields added."""
def _upload_document(self, test_run: IntegrationTestRun) -> None:
self._upsert(test_run.model_dump(by_alias=True))

def _upsert(self, doc: dict) -> None:
"""Add timestamp fields and write one document to the greenboard bucket."""
now = datetime.now(timezone.utc)
unix_timestamp = (
now - datetime(1970, 1, 1, tzinfo=timezone.utc)
Expand Down
Loading
Loading