Skip to content

Commit

Permalink
Add integration tests (#138)
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Kumar <[email protected]>
Co-authored-by: Rohit Kumar <[email protected]>
Co-authored-by: sujeet01 <[email protected]>
Co-authored-by: Kajol Asabe <[email protected]>
  • Loading branch information
4 people authored Feb 7, 2024
1 parent 1c4be40 commit c000818
Show file tree
Hide file tree
Showing 12 changed files with 1,265 additions and 56 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,53 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Setup MicroCeph
run: |
set -x
sudo snap install microceph --channel=latest/stable
sudo apt-get update
sudo apt-get install --no-install-recommends -y ceph-common
sudo microceph cluster bootstrap
sudo microceph.ceph config set global osd_pool_default_size 1
sudo microceph.ceph config set global mon_allow_pool_delete true
sudo microceph.ceph config set global osd_memory_target 939524096
sudo microceph.ceph osd crush rule rm replicated_rule
sudo microceph.ceph osd crush rule create-replicated replicated default osd
for flag in nosnaptrim noscrub nobackfill norebalance norecover noscrub nodeep-scrub; do
sudo microceph.ceph osd set $flag
done
# Repurpose the ephemeral disk for ceph OSD.
sudo swapoff /mnt/swapfile
ephemeral_disk="$(findmnt --noheadings --output SOURCE --target /mnt | sed 's/[0-9]\+$//')"
sudo microceph disk add --wipe "${ephemeral_disk}"
sudo rm -rf /etc/ceph
sudo ln -s /var/snap/microceph/current/conf/ /etc/ceph
sudo microceph enable rgw
sudo ceph osd pool create devpool 8
# Wait until there are no more "unkowns" pgs
for _ in $(seq 60); do
if sudo microceph.ceph pg stat | grep -wF unknown; then
sleep 1
else
break
fi
done
sudo microceph.ceph status
sudo rbd create --size 5000 --pool devpool test-img
sudo rm -f /snap/bin/rbd
sudo chmod 644 /etc/ceph/ceph.client.admin.keyring
- name: Set Environment Variables
run: |
echo "CEPH_MONITORS=$(hostname):6789" >> $GITHUB_ENV
echo "CEPH_IMAGE=devpool/test-img" >> $GITHUB_ENV
echo "CEPH_USERNAME=admin" >> $GITHUB_ENV
echo "CEPH_USERKEY=`ceph auth print-key client.admin`" >> $GITHUB_ENV
- name: Install dependencies
run: |
Expand Down
107 changes: 107 additions & 0 deletions provider/server/machine_annotations_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package server_test

import (
"github.com/digitalocean/go-libvirt"
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
libvirtutils "github.com/ironcore-dev/libvirt-provider/pkg/libvirt/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("UpdateMachineAnnotations", func() {
It("should update machine annotations", func(ctx SpecContext) {
ignitionData := []byte("urjhikmnbdjfkknhhdddeee")
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{
Labels: map[string]string{
"machinepoolletv1alpha1.MachineUIDLabel": "foolabel",
},
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
IgnitionData: ignitionData,
Volumes: nil,
NetworkInterfaces: nil,
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func() bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring domain and domain XML is created for machine")
var domain libvirt.Domain
Eventually(func() error {
domain, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return err
}).Should(Succeed())
domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
Expect(err).NotTo(HaveOccurred())
Expect(domainXMLData).NotTo(BeEmpty())

By("ensuring domain for machine is in running state")
Eventually(func() libvirt.DomainState {
domainState, _, err := libvirtConn.DomainGetState(domain, 0)
Expect(err).NotTo(HaveOccurred())
return libvirt.DomainState(domainState)
}).Should(Equal(libvirt.DomainRunning))

By("updating machine annotations")
_, err = machineClient.UpdateMachineAnnotations(ctx, &iri.UpdateMachineAnnotationsRequest{
MachineId: createResp.Machine.Metadata.Id,
Annotations: map[string]string{
"machinepoolletv1alpha1.MachineUIDLabel": "fooUpdatedAnnotation",
},
})
Expect(err).NotTo(HaveOccurred())

Eventually(func() bool {
listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
Filter: &iri.MachineFilter{
Id: createResp.Machine.Metadata.Id,
},
})
Expect(err).NotTo(HaveOccurred())
Expect(listResp.Machines).NotTo(BeEmpty())
Expect(listResp.Machines).Should(HaveLen(1))

machineStatus := listResp.Machines[0].Status
return machineStatus.State == iri.MachineState_MACHINE_RUNNING
}).Should(BeTrue())

By("ensuring correct annotations")
Eventually(func() *irimeta.ObjectMetadata {
listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
Filter: &iri.MachineFilter{
Id: createResp.Machine.Metadata.Id,
},
})
Expect(err).NotTo(HaveOccurred())
Expect(listResp.Machines).NotTo(BeEmpty())
Expect(listResp.Machines).Should(HaveLen(1))
return listResp.Machines[0].Metadata
}).Should(SatisfyAll(
HaveField("Annotations", Equal(map[string]string{
"machinepoolletv1alpha1.MachineUIDLabel": "fooUpdatedAnnotation",
})),
))
})
})
Loading

0 comments on commit c000818

Please sign in to comment.