Skip to content

Commit

Permalink
Merge pull request #1 from stgraber/main
Browse files Browse the repository at this point in the history
Update tests for the renamed commands
  • Loading branch information
brauner authored Aug 3, 2023
2 parents 602727a + 7e68582 commit 61a7ab7
Show file tree
Hide file tree
Showing 166 changed files with 8,991 additions and 9,013 deletions.
85 changes: 18 additions & 67 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: |
go mod download
- name: Run LXD build
- name: Run Incus build
run: |
make
Expand All @@ -73,14 +73,14 @@ jobs:
system-tests:
env:
CGO_LDFLAGS_ALLOW: "(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
LXD_SHIFTFS_DISABLE: "true"
LXD_CEPH_CLUSTER: "ceph"
LXD_CEPH_CEPHFS: "cephfs"
LXD_CEPH_CEPHOBJECT_RADOSGW: "http://127.0.0.1"
LXD_VERBOSE: "1"
LXD_OFFLINE: "1"
LXD_TMPFS: "1"
LXD_REQUIRED_TESTS: "test_storage_buckets"
INCUS_SHIFTFS_DISABLE: "true"
INCUS_CEPH_CLUSTER: "ceph"
INCUS_CEPH_CEPHFS: "cephfs"
INCUS_CEPH_CEPHOBJECT_RADOSGW: "http://127.0.0.1"
INCUS_VERBOSE: "1"
INCUS_OFFLINE: "1"
INCUS_TMPFS: "1"
INCUS_REQUIRED_TESTS: "test_storage_buckets"
name: System tests
runs-on: ubuntu-22.04
strategy:
Expand Down Expand Up @@ -186,7 +186,7 @@ jobs:
run: |
go mod download
- name: Run LXD build
- name: Run Incus build
run: |
make
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
chmod +x ~
echo "root:1000000:1000000000" | sudo tee /etc/subuid /etc/subgid
cd test
sudo --preserve-env=PATH,GOPATH,LXD_VERBOSE,LXD_BACKEND,LXD_CEPH_CLUSTER,LXD_CEPH_CEPHFS,LXD_CEPH_CEPHOBJECT_RADOSGW,LXD_OFFLINE,LXD_SKIP_TESTS,LXD_REQUIRED_TESTS,LXD_SHIFTFS_DISABLE LXD_BACKEND=${{ matrix.backend }} ./main.sh ${{ matrix.suite }}
sudo --preserve-env=PATH,GOPATH,INCUS_VERBOSE,INCUS_BACKEND,INCUS_CEPH_CLUSTER,INCUS_CEPH_CEPHFS,INCUS_CEPH_CEPHOBJECT_RADOSGW,INCUS_OFFLINE,INCUS_SKIP_TESTS,INCUS_REQUIRED_TESTS,INCUS_SHIFTFS_DISABLE INCUS_BACKEND=${{ matrix.backend }} ./main.sh ${{ matrix.suite }}
client:
name: Client tests
Expand Down Expand Up @@ -261,35 +261,35 @@ jobs:
run: |
mkdir bin
- name: Build static lxc
- name: Build static incc
env:
CGO_ENABLED: 0
run: |
go build -o bin ./lxc
go build -o bin ./inc
- name: Build static lxd-migrate
- name: Build static incus-migrate
if: runner.os == 'Linux'
env:
CGO_ENABLED: 0
run: |
go build -o bin ./lxd-migrate
go build -o bin ./incus-migrate
- name: Unit tests (client)
env:
CGO_ENABLED: 0
run: go test -v ./client/...

- name: Unit tests (lxc)
- name: Unit tests (inc)
env:
CGO_ENABLED: 0
run: go test -v ./lxc/...
run: go test -v ./inc/...

- name: Unit tests (shared)
env:
CGO_ENABLED: 0
run: go test -v ./shared/...

- name: Upload lxc client artifacts
- name: Upload inc client artifacts
uses: actions/upload-artifact@v3
continue-on-error: true
with:
Expand Down Expand Up @@ -338,52 +338,3 @@ jobs:
with:
name: documentation
path: doc/html

snap:
name: Trigger snap edge build
runs-on: ubuntu-22.04
needs: [code-tests, system-tests, client, documentation]
if: ${{ github.repository == 'canonical/lxd' && github.event_name == 'push'}}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Launchpad SSH access
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
LAUNCHPAD_LXD_BOT_KEY: ${{ secrets.LAUNCHPAD_LXD_BOT_KEY }}
run: |
ssh-agent -a "${SSH_AUTH_SOCK}" > /dev/null
ssh-add - <<< "${{ secrets.LAUNCHPAD_LXD_BOT_KEY }}"
mkdir -m 0700 -p ~/.ssh/
# In ephemeral environments like GitHub Action runners, relying on TOFU isn't providing any security
# so require the key obtained by `ssh-keyscan` to match the expected hash from https://help.launchpad.net/SSHFingerprints
ssh-keyscan git.launchpad.net >> ~/.ssh/known_hosts
ssh-keygen -qlF git.launchpad.net | grep -xF 'git.launchpad.net RSA SHA256:UNOzlP66WpDuEo34Wgs8mewypV0UzqHLsIFoqwe8dYo'
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.18.x

- name: Trigger Launchpad snap build
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
TARGET: >-
${{ fromJson('{
"main": "latest-edge",
"stable-5.0": "5.0-edge",
}')[github.ref_name] }}
run: |
set -x
git config --global user.name "Canonical LXD Bot"
git config --global user.email "[email protected]"
localRev=$(git rev-parse HEAD)
go install github.com/canonical/lxd-ci/lxd-snapcraft@latest
git clone -b "${TARGET}" git+ssh://[email protected]/~canonical-lxd/lxd ~/lxd-pkg-snap-lp
cd ~/lxd-pkg-snap-lp
lxd-snapcraft -set-version "git-${localRev:0:7}" -set-source-commit "${localRev}"
git add --all
git commit --all --quiet -s --allow-empty -m "Automatic upstream build (${TARGET})" -m "Upstream commit: ${localRev}"
git show
git push --quiet
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lxd-agent/lxd-agent
lxd-benchmark/lxd-benchmark
lxd-migrate/lxd-migrate
lxd-user/lxd-user
test/devlxd-client/devlxd-client
test/dev_incus-client/dev_incus-client
test/macaroon-identity/macaroon-identity
test/syscall/sysinfo/sysinfo

Expand Down
12 changes: 6 additions & 6 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ func ConnectLXDHTTPWithContext(ctx context.Context, args *ConnectionArgs, client

// ConnectLXDUnix lets you connect to a remote LXD daemon over a local unix socket.
//
// If the path argument is empty, then $LXD_SOCKET will be used, if
// unset $LXD_DIR/unix.socket will be used and if that one isn't set
// If the path argument is empty, then $INCUS_SOCKET will be used, if
// unset $INCUS_DIR/unix.socket will be used and if that one isn't set
// either, then the path will default to /var/lib/lxd/unix.socket.
func ConnectLXDUnix(path string, args *ConnectionArgs) (InstanceServer, error) {
return ConnectLXDUnixWithContext(context.Background(), path, args)
}

// ConnectLXDUnixWithContext lets you connect to a remote LXD daemon over a local unix socket with context.Context.
//
// If the path argument is empty, then $LXD_SOCKET will be used, if
// unset $LXD_DIR/unix.socket will be used and if that one isn't set
// If the path argument is empty, then $INCUS_SOCKET will be used, if
// unset $INCUS_DIR/unix.socket will be used and if that one isn't set
// either, then the path will default to /var/lib/lxd/unix.socket.
func ConnectLXDUnixWithContext(ctx context.Context, path string, args *ConnectionArgs) (InstanceServer, error) {
logger.Debug("Connecting to a local LXD over a Unix socket")
Expand Down Expand Up @@ -190,9 +190,9 @@ func ConnectLXDUnixWithContext(ctx context.Context, path string, args *Connectio

// Determine the socket path
if path == "" {
path = os.Getenv("LXD_SOCKET")
path = os.Getenv("INCUS_SOCKET")
if path == "" {
lxdDir := os.Getenv("LXD_DIR")
lxdDir := os.Getenv("INCUS_DIR")
if lxdDir == "" {
lxdDir = "/var/lib/lxd"
}
Expand Down
4 changes: 2 additions & 2 deletions client/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (r *ProtocolLXD) DoHTTP(req *http.Request) (*http.Response, error) {

// addClientHeaders sets headers from client settings.
// User-Agent (if r.httpUserAgent is set).
// X-LXD-authenticated (if r.requireAuthenticated is set).
// X-Incus-authenticated (if r.requireAuthenticated is set).
// Bakery authentication header and cookie (if r.bakeryClient is set).
// OIDC Authorization header (if r.oidcClient is set).
func (r *ProtocolLXD) addClientHeaders(req *http.Request) {
Expand All @@ -174,7 +174,7 @@ func (r *ProtocolLXD) addClientHeaders(req *http.Request) {
}

if r.requireAuthenticated {
req.Header.Set("X-LXD-authenticated", "true")
req.Header.Set("X-Incus-authenticated", "true")
}

if r.bakeryClient != nil {
Expand Down
12 changes: 6 additions & 6 deletions client/incus_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *ProtocolLXD) CreateContainerFromBackup(args ContainerBackupArgs) (Opera
}

req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Set("X-LXD-pool", args.PoolName)
req.Header.Set("X-Incus-pool", args.PoolName)

// Send the request
resp, err := r.DoHTTP(req)
Expand Down Expand Up @@ -864,23 +864,23 @@ func (r *ProtocolLXD) CreateContainerFile(containerName string, path string, arg

// Set the various headers
if args.UID > -1 {
req.Header.Set("X-LXD-uid", fmt.Sprintf("%d", args.UID))
req.Header.Set("X-Incus-uid", fmt.Sprintf("%d", args.UID))
}

if args.GID > -1 {
req.Header.Set("X-LXD-gid", fmt.Sprintf("%d", args.GID))
req.Header.Set("X-Incus-gid", fmt.Sprintf("%d", args.GID))
}

if args.Mode > -1 {
req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", args.Mode))
req.Header.Set("X-Incus-mode", fmt.Sprintf("%04o", args.Mode))
}

if args.Type != "" {
req.Header.Set("X-LXD-type", args.Type)
req.Header.Set("X-Incus-type", args.Type)
}

if args.WriteMode != "" {
req.Header.Set("X-LXD-write", args.WriteMode)
req.Header.Set("X-Incus-write", args.WriteMode)
}

// Send the request
Expand Down
12 changes: 6 additions & 6 deletions client/incus_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,11 @@ func (r *ProtocolLXD) CreateImage(image api.ImagesPost, args *ImageCreateArgs) (
// Setup the headers
req.Header.Set("Content-Type", contentType)
if image.Public {
req.Header.Set("X-LXD-public", "true")
req.Header.Set("X-Incus-public", "true")
}

if image.Filename != "" {
req.Header.Set("X-LXD-filename", image.Filename)
req.Header.Set("X-Incus-filename", image.Filename)
}

if len(image.Properties) > 0 {
Expand All @@ -510,7 +510,7 @@ func (r *ProtocolLXD) CreateImage(image api.ImagesPost, args *ImageCreateArgs) (
imgProps.Set(k, v)
}

req.Header.Set("X-LXD-properties", imgProps.Encode())
req.Header.Set("X-Incus-properties", imgProps.Encode())
}

if len(image.Profiles) > 0 {
Expand All @@ -520,16 +520,16 @@ func (r *ProtocolLXD) CreateImage(image api.ImagesPost, args *ImageCreateArgs) (
imgProfiles.Add("profile", v)
}

req.Header.Set("X-LXD-profiles", imgProfiles.Encode())
req.Header.Set("X-Incus-profiles", imgProfiles.Encode())
}

// Set the user agent
if image.Source != nil && image.Source.Fingerprint != "" && image.Source.Secret != "" && image.Source.Mode == "push" {
// Set fingerprint
req.Header.Set("X-LXD-fingerprint", image.Source.Fingerprint)
req.Header.Set("X-Incus-fingerprint", image.Source.Fingerprint)

// Set secret
req.Header.Set("X-LXD-secret", image.Source.Secret)
req.Header.Set("X-Incus-secret", image.Source.Secret)
}

// Send the request
Expand Down
14 changes: 7 additions & 7 deletions client/incus_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,11 @@ func (r *ProtocolLXD) CreateInstanceFromBackup(args InstanceBackupArgs) (Operati
req.Header.Set("Content-Type", "application/octet-stream")

if args.PoolName != "" {
req.Header.Set("X-LXD-pool", args.PoolName)
req.Header.Set("X-Incus-pool", args.PoolName)
}

if args.Name != "" {
req.Header.Set("X-LXD-name", args.Name)
req.Header.Set("X-Incus-name", args.Name)
}

// Send the request
Expand Down Expand Up @@ -1432,23 +1432,23 @@ func (r *ProtocolLXD) CreateInstanceFile(instanceName string, filePath string, a

// Set the various headers
if args.UID > -1 {
req.Header.Set("X-LXD-uid", fmt.Sprintf("%d", args.UID))
req.Header.Set("X-Incus-uid", fmt.Sprintf("%d", args.UID))
}

if args.GID > -1 {
req.Header.Set("X-LXD-gid", fmt.Sprintf("%d", args.GID))
req.Header.Set("X-Incus-gid", fmt.Sprintf("%d", args.GID))
}

if args.Mode > -1 {
req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", args.Mode))
req.Header.Set("X-Incus-mode", fmt.Sprintf("%04o", args.Mode))
}

if args.Type != "" {
req.Header.Set("X-LXD-type", args.Type)
req.Header.Set("X-Incus-type", args.Type)
}

if args.WriteMode != "" {
req.Header.Set("X-LXD-write", args.WriteMode)
req.Header.Set("X-Incus-write", args.WriteMode)
}

// Send the request
Expand Down
6 changes: 3 additions & 3 deletions client/incus_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (o *oidcClient) do(req *http.Request) (*http.Response, error) {
return resp, nil
}

issuer := resp.Header.Get("X-LXD-OIDC-issuer")
clientID := resp.Header.Get("X-LXD-OIDC-clientid")
audience := resp.Header.Get("X-LXD-OIDC-audience")
issuer := resp.Header.Get("X-Incus-OIDC-issuer")
clientID := resp.Header.Get("X-Incus-OIDC-clientid")
audience := resp.Header.Get("X-Incus-OIDC-audience")

err = o.refresh(issuer, clientID)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions client/incus_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,8 @@ func (r *ProtocolLXD) CreateStoragePoolVolumeFromISO(pool string, args StoragePo
}

req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Set("X-LXD-name", args.Name)
req.Header.Set("X-LXD-type", "iso")
req.Header.Set("X-Incus-name", args.Name)
req.Header.Set("X-Incus-type", "iso")

// Send the request.
resp, err := r.DoHTTP(req)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ func (r *ProtocolLXD) CreateStoragePoolVolumeFromBackup(pool string, args Storag
req.Header.Set("Content-Type", "application/octet-stream")

if args.Name != "" {
req.Header.Set("X-LXD-name", args.Name)
req.Header.Set("X-Incus-name", args.Name)
}

// Send the request.
Expand Down
Loading

0 comments on commit 61a7ab7

Please sign in to comment.