Always to a live lookup of version info instead of caching.
This commit is contained in:
parent
5d30b67a30
commit
b7bbefd9b1
@ -24,6 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/cadvisor/client"
|
||||
"github.com/google/cadvisor/client/v2"
|
||||
"github.com/google/cadvisor/integration/common"
|
||||
)
|
||||
|
||||
@ -123,12 +124,14 @@ type ShellActions interface {
|
||||
type CadvisorActions interface {
|
||||
// Returns a cAdvisor client to the machine being tested.
|
||||
Client() *client.Client
|
||||
ClientV2() *v2.Client
|
||||
}
|
||||
|
||||
type realFramework struct {
|
||||
hostname HostnameInfo
|
||||
t *testing.T
|
||||
cadvisorClient *client.Client
|
||||
cadvisorClientV2 *v2.Client
|
||||
|
||||
shellActions shellActions
|
||||
dockerActions dockerActions
|
||||
@ -195,6 +198,18 @@ func (self *realFramework) Client() *client.Client {
|
||||
return self.cadvisorClient
|
||||
}
|
||||
|
||||
// Gets a v2 client to the cAdvisor being tested.
|
||||
func (self *realFramework) ClientV2() *v2.Client {
|
||||
if self.cadvisorClientV2 == nil {
|
||||
cadvisorClientV2, err := v2.NewClient(self.Hostname().FullHostname())
|
||||
if err != nil {
|
||||
self.t.Fatalf("Failed to instantiate the cAdvisor client: %v", err)
|
||||
}
|
||||
self.cadvisorClientV2 = cadvisorClientV2
|
||||
}
|
||||
return self.cadvisorClientV2
|
||||
}
|
||||
|
||||
func (self dockerActions) RunPause() string {
|
||||
return self.Run(DockerRunArgs{
|
||||
Image: "kubernetes/pause",
|
||||
|
36
integration/tests/api/attributes_test.go
Normal file
36
integration/tests/api/attributes_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/cadvisor/integration/framework"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAttributeInformationIsReturned(t *testing.T) {
|
||||
fm := framework.New(t)
|
||||
defer fm.Cleanup()
|
||||
|
||||
attributes, err := fm.Cadvisor().ClientV2().Attributes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vp := `\d+\.\d+\.\d+`
|
||||
assert.True(t, assert.Regexp(t, vp, attributes.DockerVersion),
|
||||
"Expected %s to match %s", attributes.DockerVersion, vp)
|
||||
}
|
@ -161,8 +161,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newManager.versionInfo = *versionInfo
|
||||
glog.Infof("Version: %+v", newManager.versionInfo)
|
||||
glog.Infof("Version: %+v", *versionInfo)
|
||||
|
||||
newManager.eventHandler = events.NewEventManager(parseEventsStoragePolicy())
|
||||
return newManager, nil
|
||||
@ -183,7 +182,6 @@ type manager struct {
|
||||
memoryCache *memory.InMemoryCache
|
||||
fsInfo fs.FsInfo
|
||||
machineInfo info.MachineInfo
|
||||
versionInfo info.VersionInfo
|
||||
quitChannels []chan error
|
||||
cadvisorContainer string
|
||||
inHostNamespace bool
|
||||
@ -658,7 +656,11 @@ func (m *manager) GetMachineInfo() (*info.MachineInfo, error) {
|
||||
}
|
||||
|
||||
func (m *manager) GetVersionInfo() (*info.VersionInfo, error) {
|
||||
return &m.versionInfo, nil
|
||||
// TODO: Consider caching this and periodically updating. The VersionInfo may change if
|
||||
// the docker daemon is started after the cAdvisor client is created. Caching the value
|
||||
// would be helpful so we would be able to return the last known docker version if
|
||||
// docker was down at the time of a query.
|
||||
return getVersionInfo()
|
||||
}
|
||||
|
||||
func (m *manager) Exists(containerName string) bool {
|
||||
@ -1149,8 +1151,12 @@ func (m *manager) DockerInfo() (DockerStatus, error) {
|
||||
if err != nil {
|
||||
return DockerStatus{}, err
|
||||
}
|
||||
versionInfo, err := m.GetVersionInfo()
|
||||
if err != nil {
|
||||
return DockerStatus{}, err
|
||||
}
|
||||
out := DockerStatus{}
|
||||
out.Version = m.versionInfo.DockerVersion
|
||||
out.Version = versionInfo.DockerVersion
|
||||
if val, ok := info["KernelVersion"]; ok {
|
||||
out.KernelVersion = val
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user