mirror of
https://github.com/google/glazier.git
synced 2026-04-04 20:00:01 -04:00
Merge branch 'master' into test_513611839
This commit is contained in:
@@ -203,7 +203,7 @@ class BuildInfo(object):
|
||||
except files.Error as e:
|
||||
raise YamlFileError(rel_id_file) from e
|
||||
if data and 'release_id' in data:
|
||||
return data['release_id']
|
||||
return data['release_id'] # pytype: disable=unsupported-operands # always-use-return-annotations
|
||||
return None
|
||||
|
||||
def _ReleaseInfo(self):
|
||||
|
||||
@@ -134,11 +134,11 @@ class ConfigBuilder(base.ConfigBase):
|
||||
'SetTimer': [timer_start]
|
||||
}
|
||||
})
|
||||
controls = yaml_config['controls']
|
||||
controls = yaml_config['controls'] # pytype: disable=unsupported-operands # always-use-return-annotations
|
||||
try:
|
||||
for control in controls:
|
||||
if 'pin' not in control or self._MatchPin(control['pin']):
|
||||
self._StoreControls(control, yaml_config.get('templates'))
|
||||
self._StoreControls(control, yaml_config.get('templates')) # pytype: disable=attribute-error # always-use-return-annotations
|
||||
finally:
|
||||
# close out any timers before raising a server change
|
||||
timer_stop = 'stop_{}_{}'.format(conf_path.rstrip('/'), conf_file)
|
||||
|
||||
@@ -97,8 +97,8 @@ class ConfigRunner(config_base.ConfigBase):
|
||||
raise CheckUrlError(url=url)
|
||||
|
||||
while tasks:
|
||||
self._build_info.ActiveConfigPath(set_to=tasks[0]['path'])
|
||||
entry = tasks[0]['data']
|
||||
self._build_info.ActiveConfigPath(set_to=tasks[0]['path']) # pytype: disable=unsupported-operands # always-use-return-annotations
|
||||
entry = tasks[0]['data'] # pytype: disable=unsupported-operands # always-use-return-annotations
|
||||
for element in entry:
|
||||
if element == 'policy':
|
||||
for line in entry['policy']:
|
||||
|
||||
@@ -77,7 +77,7 @@ flags.DEFINE_string('ntp_server', 'time.google.com',
|
||||
flags.DEFINE_list(
|
||||
'verify_urls',
|
||||
[
|
||||
'https://www.microsoft.com',
|
||||
'https://dns.google',
|
||||
],
|
||||
'Comma-separated list of URLs to verify are reachable at start',
|
||||
)
|
||||
|
||||
@@ -81,17 +81,20 @@ func AddRepo(name, url string, conf *Config) error {
|
||||
}
|
||||
|
||||
// Install installs a Googet package.
|
||||
func Install(pkg, sources string, reinstall bool, conf *Config) error {
|
||||
func Install(pkg, sources string, reinstall bool, dbOnly bool, conf *Config) error {
|
||||
if conf == nil {
|
||||
conf = NewConfig()
|
||||
}
|
||||
|
||||
cmd := []string{"-noconfirm", "install"}
|
||||
if reinstall {
|
||||
cmd = append(cmd, "--reinstall")
|
||||
cmd = append(cmd, "-reinstall")
|
||||
}
|
||||
if sources != "" {
|
||||
cmd = append(cmd, "--sources", sources)
|
||||
cmd = append(cmd, "-sources", sources)
|
||||
}
|
||||
if dbOnly {
|
||||
cmd = append(cmd, "-db_only")
|
||||
}
|
||||
cmd = append(cmd, pkg)
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func TestInstall(t *testing.T) {
|
||||
pkg string
|
||||
sources string
|
||||
reinstall bool
|
||||
dbOnly bool
|
||||
wantArg []string
|
||||
wantErr error
|
||||
}{
|
||||
@@ -34,14 +35,24 @@ func TestInstall(t *testing.T) {
|
||||
pkg: "pkg-one",
|
||||
sources: "http://repo/manifest/url",
|
||||
reinstall: false,
|
||||
wantArg: []string{"-noconfirm", "install", "--sources", "http://repo/manifest/url", "pkg-one"},
|
||||
dbOnly: false,
|
||||
wantArg: []string{"-noconfirm", "install", "-sources", "http://repo/manifest/url", "pkg-one"},
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
pkg: "pkg-two",
|
||||
sources: "",
|
||||
reinstall: true,
|
||||
wantArg: []string{"-noconfirm", "install", "--reinstall", "pkg-two"},
|
||||
dbOnly: false,
|
||||
wantArg: []string{"-noconfirm", "install", "-reinstall", "pkg-two"},
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
pkg: "pkg-three",
|
||||
sources: "",
|
||||
reinstall: false,
|
||||
dbOnly: true,
|
||||
wantArg: []string{"-noconfirm", "install", "-db_only", "pkg-three"},
|
||||
wantErr: nil,
|
||||
},
|
||||
}
|
||||
@@ -51,7 +62,7 @@ func TestInstall(t *testing.T) {
|
||||
a = args
|
||||
return helpers.ExecResult{}, nil
|
||||
}
|
||||
err := Install(tt.pkg, tt.sources, tt.reinstall, nil)
|
||||
err := Install(tt.pkg, tt.sources, tt.reinstall, tt.dbOnly, nil)
|
||||
if !cmp.Equal(a, tt.wantArg) {
|
||||
t.Errorf("Install(%s) produced unexpected differences (-want +got): %s", tt.pkg, cmp.Diff(tt.wantArg, a))
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
// Package stages allows interacting with Glazier build stages.
|
||||
@@ -27,6 +28,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// StartKey references the time that the stage started
|
||||
StartKey = "Start"
|
||||
// EndKey references the time that the stage ended
|
||||
EndKey = "End"
|
||||
|
||||
defaultTimeout = 60 * 24 * 7 * time.Minute // 7 days
|
||||
regStagesRoot = `SOFTWARE\Glazier\Stages`
|
||||
regActiveKey = "_Active"
|
||||
@@ -56,7 +62,7 @@ func NewStage() *Stage {
|
||||
|
||||
func activeTimeFromReg(root, stageID string, period string) (time.Time, error) {
|
||||
switch period {
|
||||
case "Start", "End":
|
||||
case StartKey, EndKey:
|
||||
active, err := registry.GetString(fmt.Sprintf(`%s\%s`, root, stageID), period)
|
||||
if err != nil && err != registry.ErrNotExist {
|
||||
return time.Time{}, err
|
||||
@@ -80,11 +86,11 @@ func activeTimeFromReg(root, stageID string, period string) (time.Time, error) {
|
||||
func (s *Stage) RetreiveTimes(root, stageID string) error {
|
||||
var err error
|
||||
|
||||
if s.Start, err = activeTimeFromReg(root, stageID, "Start"); err != nil {
|
||||
if s.Start, err = activeTimeFromReg(root, stageID, StartKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.End, err = activeTimeFromReg(root, stageID, "End"); err != nil {
|
||||
if s.End, err = activeTimeFromReg(root, stageID, EndKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -156,3 +162,32 @@ func ActiveStatus() (*Stage, error) {
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// SetStage creates or updates the passed build stage in a database.
|
||||
func SetStage(stageID string, period string) error {
|
||||
key := fmt.Sprintf(`%s\%s`, regStagesRoot, stageID)
|
||||
time := time.Now().Format(timeFmt)
|
||||
activeValue := stageID
|
||||
|
||||
if period != StartKey && period != EndKey {
|
||||
return ErrPeriod
|
||||
}
|
||||
|
||||
if period == EndKey {
|
||||
activeValue = ""
|
||||
}
|
||||
|
||||
if err := registry.Create(key); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := registry.SetString(key, period, time); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := registry.SetString(regStagesRoot, regActiveKey, activeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// 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
|
||||
// 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,
|
||||
@@ -250,3 +250,38 @@ func TestRetreiveTimesNoKey(t *testing.T) {
|
||||
t.Errorf("%s(): raised unexpected error %v", testID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStage(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
in string
|
||||
period string
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
desc: "start period",
|
||||
in: "1336",
|
||||
period: StartKey,
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
desc: "end period",
|
||||
in: "1337",
|
||||
period: EndKey,
|
||||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
desc: "invalid period",
|
||||
in: "1338",
|
||||
period: "Foo",
|
||||
wantErr: ErrPeriod,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
err := SetStage(tt.in, tt.period)
|
||||
if !errors.Is(err, tt.wantErr) {
|
||||
t.Errorf("SetStage(%v, %v) returned unexpected error %v", tt.in, tt.period, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user