Skip to content

Commit

Permalink
Merge pull request kubevirt#3973 from xpivarc/fix-clock-timezone
Browse files Browse the repository at this point in the history
Fix clock timezone
  • Loading branch information
kubevirt-bot authored Aug 13, 2020
2 parents 2bb4b0d + 4c6c416 commit f4b3eac
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ func Convert_v1_Clock_To_api_Clock(source *v1.Clock, clock *Clock, c *ConverterC
}
} else if source.Timezone != nil {
clock.Offset = "timezone"
clock.Timezone = string(*source.Timezone)
}

if source.Timer != nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/virt-launcher/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ var _ = Describe("Converter", func() {

TestSmbios := &cmdv1.SMBios{}

Context("with timezone", func() {
It("Should set timezone attribute", func() {
timezone := v1.ClockOffsetTimezone("America/New_York")
clock := &v1.Clock{
ClockOffset: v1.ClockOffset{
Timezone: &timezone,
},
Timer: &v1.Timer{},
}

var convertClock Clock
Convert_v1_Clock_To_api_Clock(clock, &convertClock, &ConverterContext{})
data, err := xml.MarshalIndent(convertClock, "", " ")
Expect(err).ToNot(HaveOccurred())

expectedClock := `<Clock offset="timezone" timezone="America/New_York"></Clock>`
Expect(string(data)).To(Equal(expectedClock))
})
})

Context("with v1.Disk", func() {
It("Should add boot order when provided", func() {
order := uint(1)
Expand Down
1 change: 1 addition & 0 deletions pkg/virt-launcher/virtwrap/api/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ type Entry struct {

type Clock struct {
Offset string `xml:"offset,attr,omitempty"`
Timezone string `xml:"timezone,attr,omitempty"`
Adjustment string `xml:"adjustment,attr,omitempty"`
Timer []Timer `xml:"timer,omitempty"`
}
Expand Down
40 changes: 40 additions & 0 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,46 @@ var _ = Describe("Configurations", func() {
})
})

Context("with Clock and timezone", func() {

It("guest should see timezone", func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
timezone := "America/New_York"
tz := v1.ClockOffsetTimezone(timezone)
vmi.Spec.Domain.Clock = &v1.Clock{
ClockOffset: v1.ClockOffset{
Timezone: &tz,
},
Timer: &v1.Timer{},
}

By("Creating a VMI with timezone set")
vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())

By("Waiting for succesful start of VMI")
tests.WaitForSuccessfulVMIStart(vmi)

By("Logging to VMI")
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()

loc, err := time.LoadLocation(timezone)
Expect(err).ToNot(HaveOccurred())
now := time.Now().In(loc)

By("Checking hardware clock time")
expected := fmt.Sprintf("%02d:%02d:", now.Hour(), now.Minute())
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "sudo hwclock --localtime \n"},
&expect.BExp{R: expected},
}, 15*time.Second)
Expect(err).ToNot(HaveOccurred())

})
})

})

Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with CPU spec", func() {
Expand Down

0 comments on commit f4b3eac

Please sign in to comment.