Skip to content

Commit

Permalink
spread: fix TestOpenstackFindImageComplex test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Sep 25, 2023
1 parent 2d98f1b commit 463c503
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
16 changes: 13 additions & 3 deletions spread/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"regexp"
"time"

"github.com/go-goose/goose/v5/glance"
Expand Down Expand Up @@ -121,12 +122,21 @@ func uuid() string {
return string(b)
}

var fakeImageDetailsDateRegex = regexp.MustCompile(`.*-([0-9]+)-.*`)

func makeGlanceImageDetails(imgs []string) []glance.ImageDetail {
out := make([]glance.ImageDetail, len(imgs))
for i, name := range imgs {
// XXX: is this correct? the id is just a uuid?
var created string

id := uuid()
out[i] = glance.ImageDetail{Id: id, Name: name}
match := fakeImageDetailsDateRegex.FindStringSubmatch(name)
if match != nil {
if t, err := time.Parse("20060102", match[1]); err == nil {
created = t.Format(time.RFC3339)
}
}
out[i] = glance.ImageDetail{Id: id, Name: name, Created: created}
}
return out
}
Expand Down Expand Up @@ -181,7 +191,7 @@ func (s *openstackFindImageSuite) TestOpenstackFindImageComplex(c *C) {
// simple string match of name
{"ubuntu-22.04", fakeOpenstackImageList, "auto-sync/ubuntu-22.04-something"},
// complex sorting based on date of the images
{"ubuntu-bionic-18.04-amd64", fakeOpenstackImageList, "auto-sync/ubuntu-bionic-18.04-amd64-server-20210928-disk1.img"},
{"ubuntu-bionic-18.04-amd64", fakeOpenstackImageList, "auto-sync/ubuntu-bionic-18.04-amd64-server-20230530-disk1.img"},
} {
s.fakeImageClient.res = makeGlanceImageDetails(tc.availableImages)
idt, err := s.opst.FindImage(tc.imageName)
Expand Down
41 changes: 6 additions & 35 deletions tests/openstack/spread.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
project: spread

backends:
openstack:
plan: m1.tiny
halt-timeout: 1s
systems:
- cirros-64:
image: cirros-0.6.2-x86_64-disk
groups:
- default
networks:
- private
- cirros-64-wrong-network:
image: cirros-0.6.2-x86_64-disk
groups:
- default
networks:
- noexist
- cirros-64-wrong-group:
image: cirros-0.6.2-x86_64-disk
groups:
- noexist
networks:
- private
- cirros-64-wrong-image:
image: noexist
groups:
- default
networks:
- private
- cirros-64-wrong-plan:
image: cirros-0.6.2-x86_64-disk
plan: noexist
groups:
- default
networks:
- private
openstack:
plan: m1.tiny
halt-timeout: 1s
systems:
- cirros-64:
image: cirros-0.6.2-x86_64-disk


path: /home/openstack
Expand Down

0 comments on commit 463c503

Please sign in to comment.