Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust] Automated Edge management (#11681 and #11683) #12835

Merged
merged 35 commits into from
Oct 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0668c6a
[rust] Automated Edge management (macOS) (#11681)
bonigarcia Sep 19, 2023
9a5ae46
[rust] Check also unstable versions for Edge management
bonigarcia Sep 19, 2023
501ffe6
[rust] Include logic to check fixed versions of Edge
bonigarcia Sep 19, 2023
b0d03e9
[rust] Include additional log messages
bonigarcia Sep 19, 2023
b277e8c
[rust] Get browser url again if empty
bonigarcia Sep 19, 2023
1d1a905
[rust] Include logic for stable label
bonigarcia Sep 20, 2023
64b282a
[rust] Automated Edge management (Linux) (#11681 and #11683)
bonigarcia Sep 24, 2023
1445fae
[rust] Fix paths used to extract edge
bonigarcia Sep 24, 2023
72ad82c
[rust] Clean extract label and fix searched version
bonigarcia Sep 27, 2023
12f9dab
[rust] Refactor logic for downloading browsers in a common function
bonigarcia Sep 28, 2023
21c23a9
[rust] Install Edge in Windows through the MSI installer
bonigarcia Sep 28, 2023
a55c408
[rust] Check admin permissions in Windows before downloading MSI inst…
bonigarcia Sep 28, 2023
b5b58b8
[rust] Include tests for managing Edge
bonigarcia Sep 28, 2023
6f35235
[rust] Use browser version in functions for requesting online repos
bonigarcia Sep 28, 2023
8f47db3
[rust] Refactor common logic when unavailable download or discovery
bonigarcia Sep 29, 2023
baa4651
[rust] Improve a couple of logging messages
bonigarcia Sep 29, 2023
90bbf8e
[rust] Fix condition checking Firefox nightly in mac
bonigarcia Sep 29, 2023
329abdf
[rust] Update cargo bazel lock fil
bonigarcia Sep 29, 2023
a508aac
[rust] Ensure empty parent path before moving files
bonigarcia Sep 29, 2023
1d71373
Revert "[rust] Ensure empty parent path before moving files"
bonigarcia Sep 29, 2023
c7565bb
[rust] Separate function to tnsure empty parent path before moving files
bonigarcia Sep 29, 2023
bb9f0d0
[rust] Revert function to create parent path in grid logic
bonigarcia Sep 29, 2023
514b29f
[rust] Fix logic to create empty parent path
bonigarcia Sep 30, 2023
2cf7a07
[rust] Fix problems after rebasing
bonigarcia Oct 6, 2023
efdc4f1
[ci] try without reusing docker in the tests
titusfortner Oct 6, 2023
3f2835c
[ci] run rbe with selenium manager in offline mode
titusfortner Oct 6, 2023
9fe3e52
[ci] set the input the correct way
titusfortner Oct 6, 2023
a35754d
try setting environment variable in bazelrc
titusfortner Oct 6, 2023
3fb7df2
turn off network on remote build
titusfortner Oct 6, 2023
42cb176
try setting the env in build as well as test
titusfortner Oct 6, 2023
cf27b9c
none of this worked
titusfortner Oct 7, 2023
5da0dc3
turn off selenium manager in test
titusfortner Oct 7, 2023
5c3f06a
fix linter issue
titusfortner Oct 7, 2023
8087dab
Merge branch 'trunk' into sm_edge_management
titusfortner Oct 7, 2023
8443a2b
Merge branch 'trunk' into sm_edge_management
titusfortner Oct 7, 2023
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
Prev Previous commit
Next Next commit
[rust] Refactor logic for downloading browsers in a common function
bonigarcia committed Oct 6, 2023
commit 12f9dab917263588755fee9bf207a91432cc0d02
168 changes: 40 additions & 128 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
@@ -32,9 +32,8 @@ use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
};
use crate::{
create_browser_metadata, create_http_client, download_to_tmp_folder, format_three_args,
get_browser_version_from_metadata, uncompress, SeleniumManager, BETA, DASH_DASH_VERSION, DEV,
NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_VERSION_ARG, STABLE,
create_http_client, format_three_args, SeleniumManager, BETA, DASH_DASH_VERSION, DEV, NIGHTLY,
OFFLINE_REQUEST_ERR_MSG, REG_VERSION_ARG, STABLE, UNAVAILABLE_DOWNLOAD_WITH_VERSION_ERR_MSG,
};

pub const CHROME_NAME: &str = "chrome";
@@ -48,8 +47,6 @@ const CFT_MACOS_APP_NAME: &str =
"Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing";
const MIN_CHROME_VERSION_CFT: i32 = 113;
const MIN_CHROMEDRIVER_VERSION_CFT: i32 = 115;
const UNAVAILABLE_CFT_ERROR_MESSAGE: &str =
"{} {} not available for download in Chrome for Testing (minimum version: {})";

pub struct ChromeManager {
pub browser_name: &'static str,
@@ -173,7 +170,7 @@ impl ChromeManager {
.collect();
if filtered_versions.is_empty() {
return Err(format_three_args(
UNAVAILABLE_CFT_ERROR_MESSAGE,
UNAVAILABLE_DOWNLOAD_WITH_VERSION_ERR_MSG,
self.get_driver_name(),
&version_for_filtering,
&MIN_CHROMEDRIVER_VERSION_CFT.to_string(),
@@ -195,15 +192,6 @@ impl ChromeManager {

Ok(driver_version.version.to_string())
}

fn get_browser_binary_path_in_cache(&self) -> Result<PathBuf, Box<dyn Error>> {
let browser_in_cache = self.get_browser_path_in_cache()?;
if MACOS.is(self.get_os()) {
Ok(browser_in_cache.join(CFT_MACOS_APP_NAME))
} else {
Ok(browser_in_cache.join(self.get_browser_name_with_extension()))
}
}
}

impl SeleniumManager for ChromeManager {
@@ -410,118 +398,6 @@ impl SeleniumManager for ChromeManager {
self.log = log;
}

fn download_browser(&mut self) -> Result<Option<PathBuf>, Box<dyn Error>> {
let browser_version;
let browser_name = self.browser_name;
let cache_path = self.get_cache_path()?;
let mut metadata = get_metadata(self.get_logger(), &cache_path);
let major_browser_version = self.get_major_browser_version();
let major_browser_version_int = major_browser_version.parse::<i32>().unwrap_or_default();

// Browser version should be available in the CfT endpoints (>= 113)
if !self.is_browser_version_unstable()
&& !self.is_browser_version_stable()
&& !self.is_browser_version_empty()
&& major_browser_version_int < MIN_CHROME_VERSION_CFT
{
return Err(format_three_args(
UNAVAILABLE_CFT_ERROR_MESSAGE,
browser_name,
&major_browser_version,
&MIN_CHROME_VERSION_CFT.to_string(),
)
.into());
}

// Browser version is checked in the local metadata
match get_browser_version_from_metadata(
&metadata.browsers,
browser_name,
&major_browser_version,
) {
Some(version) => {
self.get_logger().trace(format!(
"Browser with valid TTL. Getting {} version from metadata",
browser_name
));
browser_version = version;
self.set_browser_version(browser_version.clone());
}
_ => {
// If not in metadata, discover version using Chrome for Testing (CfT) endpoints
if self.is_browser_version_stable() || self.is_browser_version_empty() {
browser_version = self.request_latest_browser_version_from_online()?;
} else {
browser_version = self.request_fixed_browser_version_from_online()?;
}
self.set_browser_version(browser_version.clone());

let browser_ttl = self.get_ttl();
if browser_ttl > 0
&& !self.is_browser_version_empty()
&& !self.is_browser_version_stable()
{
metadata.browsers.push(create_browser_metadata(
browser_name,
&major_browser_version,
&browser_version,
browser_ttl,
));
write_metadata(&metadata, self.get_logger(), cache_path);
}
}
}
self.get_logger().debug(format!(
"Required browser: {} {}",
browser_name, browser_version
));

// Checking if browser version is in the cache
let browser_binary_path = self.get_browser_binary_path_in_cache()?;
if browser_binary_path.exists() {
self.get_logger().debug(format!(
"{} {} already in the cache",
browser_name, browser_version
));
} else {
// If browser is not in the cache, download it
let browser_url = if let Some(url) = self.browser_url.clone() {
url
} else {
if self.is_browser_version_stable() || self.is_browser_version_empty() {
self.request_latest_browser_version_from_online()?;
} else {
self.request_fixed_browser_version_from_online()?;
}
self.browser_url.clone().unwrap()
};
self.get_logger().debug(format!(
"Downloading {} {} from {}",
self.get_browser_name(),
self.get_browser_version(),
browser_url
));
let (_tmp_folder, driver_zip_file) =
download_to_tmp_folder(self.get_http_client(), browser_url, self.get_logger())?;

uncompress(
&driver_zip_file,
&self.get_browser_path_in_cache()?,
self.get_logger(),
self.get_os(),
None,
None,
None,
)?;
}
if browser_binary_path.exists() {
self.set_browser_path(path_to_string(&browser_binary_path));
Ok(Some(browser_binary_path))
} else {
Ok(None)
}
}

fn get_platform_label(&self) -> &str {
let os = self.get_os();
let arch = self.get_arch();
@@ -611,7 +487,7 @@ impl SeleniumManager for ChromeManager {
.collect();
if filtered_versions.is_empty() {
return Err(format_three_args(
UNAVAILABLE_CFT_ERROR_MESSAGE,
UNAVAILABLE_DOWNLOAD_WITH_VERSION_ERR_MSG,
browser_name,
&major_browser_version,
&MIN_CHROME_VERSION_CFT.to_string(),
@@ -630,6 +506,42 @@ impl SeleniumManager for ChromeManager {
Ok(last_browser.version.to_string())
}
}

fn get_min_browser_version_for_download(&self) -> Result<i32, Box<dyn Error>> {
Ok(MIN_CHROME_VERSION_CFT)
}

fn get_browser_binary_path(&self, _browser_version: &str) -> Result<PathBuf, Box<dyn Error>> {
let browser_in_cache = self.get_browser_path_in_cache()?;
if MACOS.is(self.get_os()) {
Ok(browser_in_cache.join(CFT_MACOS_APP_NAME))
} else {
Ok(browser_in_cache.join(self.get_browser_name_with_extension()))
}
}

fn get_browser_url_for_download(
&mut self,
_browser_version: &str,
) -> Result<String, Box<dyn Error>> {
if let Some(browser_url) = self.browser_url.clone() {
Ok(browser_url)
} else {
if self.is_browser_version_stable() || self.is_browser_version_empty() {
self.request_latest_browser_version_from_online()?;
} else {
self.request_fixed_browser_version_from_online()?;
}
Ok(self.browser_url.clone().unwrap())
}
}

fn get_browser_label_for_download(
&self,
_browser_version: &str,
) -> Result<Option<&str>, Box<dyn Error>> {
Ok(None)
}
}

#[derive(Serialize, Deserialize)]
Loading