This is an archive of the discontinued Mercurial Phabricator instance.

automation: perform tasks on remote machines
ClosedPublic

Authored by indygreg on Mar 15 2019, 2:25 PM.

Details

Summary

Sometimes you don't have access to a machine in order to
do something. For example, you may not have access to a Windows
machine required to build Windows binaries or run tests on that
platform.

This commit introduces a pile of code intended to help
"automate" common tasks, like building release artifacts.

In its current form, the automation code provides functionality
for performing tasks on Windows EC2 instances.

The hgautomation.aws module provides functionality for integrating
with AWS. It manages EC2 resources such as IAM roles, EC2
security groups, AMIs, and instances.

The hgautomation.windows module provides a higher-level
interface for performing tasks on remote Windows machines.

The hgautomation.cli module provides a command-line interface to
these higher-level primitives.

I attempted to structure Windows remote machine interaction
around Windows Remoting / PowerShell. This is kinda/sorta like
SSH + shell, but for Windows. In theory, most of the functionality
is cloud provider agnostic, as we should be able to use any
established WinRM connection to interact with a remote. In
reality, we're tightly coupled to AWS at the moment because
I didn't want to prematurely add abstractions for a 2nd cloud
provider. (1 was hard enough to implement.)

In the aws module is code for creating an image with a fully
functional Mercurial development environment. It contains VC9,
VC2017, msys, and other dependencies. The image is fully capable
of building all the existing Mercurial release artifacts and
running tests.

There are a few things that don't work. For example, running
Windows tests with Python 3. But building the Windows release
artifacts does work. And that was an impetus for this work.
(Although we don't yet support code signing.)

Getting this functionality to work was extremely time consuming.
It took hours debugging permissions failures and other wonky
behavior due to PowerShell Remoting. (The permissions model for
PowerShell is crazy and you brush up against all kinds of
issues because of the user/privileges of the user running
the PowerShell and the permissions of the PowerShell session
itself.)

The functionality around AWS resource management could use some
improving. In theory we support shared tenancy via resource
name prefixing. In reality, we don't offer a way to configure
this.

Speaking of AWS resource management, I thought about using a tool
like Terraform to manage resources. But at our scale, writing a
few dozen lines of code to manage resources seemed acceptable.
Maybe we should reconsider this if things grow out of control.
Time will tell.

Currently, emphasis is placed on Windows. But I only started
there because it was likely to be the most difficult to implement.
It should be relatively trivial to automate tasks on remote Linux
machines. In fact, I have a ~1 year old script to run tests on a
remote EC2 instance. I will likely be porting that to this new
"framework" in the near future.

  1. no-check-commit because foo_bar functions

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Mar 15 2019, 2:25 PM

I don't know anything about PowerShell or AWS, but this series looks nice for making Windows easier to deal with.

What was the problem with python3 tests? I've been able to run them locally (though a bunch fail with py3 issues).

I've been hacking on and off with running tests under WSL. I'm not sure if that will help any of this. It's tantalizingly close, but there are path style issues that WSLENV and wslpath can't fix. (e.g., sometimes $TESTTMP is written to an hgrc file in Linux format, and hg.exe can't understand that.)

Any plans to port this to the TortoiseHg codebase? I don't have the bandwidth to try anything in the near term, but don't want to duplicate effort.

contrib/automation/hgautomation/windows.py
98

There's an annoying issue with MSYS where it will convert the username part of %TEMP% and %TMP% to 8.3 format with a ~ if it is long-ish. That throws a few tests into disarray. Given how MSYS is bootstrapped here, I wonder if those variables can be set to C:\hgdev\tmp or similar first.

I don't know anything about PowerShell or AWS, but this series looks nice for making Windows easier to deal with.
What was the problem with python3 tests? I've been able to run them locally (though a bunch fail with py3 issues).

It had something to do with the MSVC environment not being "activated." I believe link.exe couldn't find rc.exe or something like that. I suspect this is a distutils limitation or something in our setup.py not playing well with Python 3. It probably isn't too difficult to fix - I just haven't spent the time on it yet.

I've been hacking on and off with running tests under WSL. I'm not sure if that will help any of this. It's tantalizingly close, but there are path style issues that WSLENV and wslpath can't fix. (e.g., sometimes $TESTTMP is written to an hgrc file in Linux format, and hg.exe can't understand that.)

I thought about configuring WSL in the base environment. But I figured that would be best left as a follow-up since WSL isn't well supported at the moment and I didn't want to spend time going down that rabbit hole.

Any plans to port this to the TortoiseHg codebase? I don't have the bandwidth to try anything in the near term, but don't want to duplicate effort.

I reached out to Steve Borho about the recent packaging work. I believe I offered support to port thg-winbuild to the new mechanism. I don't believe I've heard back yet. I would not be opposed to moving some/more of the TortoiseHg packaging bits into the core distribution. I'm not sure how others feel about that. I definitely want to make TortoiseHg packaging as simple as possible and buffered against upstream changes.

This revision was automatically updated to reflect the committed changes.