github.com/coreos/mantle@v0.13.0/kola/tests/util/rpmostree.go (about) 1 // Copyright 2018 Red Hat, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package util 16 17 import ( 18 "encoding/json" 19 "fmt" 20 21 "github.com/coreos/mantle/kola/cluster" 22 "github.com/coreos/mantle/platform" 23 ) 24 25 // rpmOstreeDeployment represents some of the data of an rpm-ostree deployment 26 type rpmOstreeDeployment struct { 27 Booted bool `json:"booted"` 28 Checksum string `json:"checksum"` 29 Origin string `json:"origin"` 30 Osname string `json:"osname"` 31 Packages []string `json:"packages"` 32 RequestedPackages []string `json:"requested-packages"` 33 Timestamp int64 `json:"timestamp"` 34 Unlocked string `json:"unlocked"` 35 Version string `json:"version"` 36 } 37 38 // simplifiedRpmOstreeStatus contains deployments from rpm-ostree status 39 type simplifiedRpmOstreeStatus struct { 40 Deployments []rpmOstreeDeployment 41 } 42 43 // GetRpmOstreeStatusJSON returns an unmarshal'ed JSON object that contains 44 // a limited representation of the output of `rpm-ostree status --json` 45 func GetRpmOstreeStatusJSON(c cluster.TestCluster, m platform.Machine) (simplifiedRpmOstreeStatus, error) { 46 target := simplifiedRpmOstreeStatus{} 47 rpmOstreeJSON, err := c.SSH(m, "rpm-ostree status --json") 48 if err != nil { 49 return target, fmt.Errorf("Could not get rpm-ostree status: %v", err) 50 } 51 52 err = json.Unmarshal(rpmOstreeJSON, &target) 53 if err != nil { 54 return target, fmt.Errorf("Couldn't umarshal the rpm-ostree status JSON data: %v", err) 55 } 56 57 return target, nil 58 }