From da9786dab594cc66d3fb95ed9f87bdaebe9ef6f9 Mon Sep 17 00:00:00 2001 From: YanzhaoLi Date: Fri, 26 Apr 2019 00:54:14 -0700 Subject: [PATCH] Revert "Add --syslog to vic-machine configure (#8512)" This reverts commit 1d749af3a0960d71f75fd9536dbcf10090baee9d. --- cmd/vic-machine/common/syslog.go | 51 ------------------- cmd/vic-machine/common/syslog_test.go | 27 ---------- cmd/vic-machine/configure/configure.go | 18 ++----- cmd/vic-machine/create/create.go | 31 +++++++++-- cmd/vic-machine/create/create_test.go | 7 +++ .../service/restapi/handlers/vch_create.go | 6 +-- .../restapi/handlers/vch_create_test.go | 5 +- lib/install/data/data.go | 2 - .../Group6-VIC-Machine/6-15-Syslog.robot | 24 ++------- 9 files changed, 43 insertions(+), 128 deletions(-) delete mode 100644 cmd/vic-machine/common/syslog.go delete mode 100644 cmd/vic-machine/common/syslog_test.go diff --git a/cmd/vic-machine/common/syslog.go b/cmd/vic-machine/common/syslog.go deleted file mode 100644 index 26cdc5fc71..0000000000 --- a/cmd/vic-machine/common/syslog.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2019 VMware, 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 common - -import ( - "net/url" - - "gopkg.in/urfave/cli.v1" -) - -// general syslog -type Syslog struct { - SyslogAddr string -} - -func (s *Syslog) SyslogFlags() []cli.Flag { - return []cli.Flag{ - cli.StringFlag{ - Name: "syslog-address", - Value: "", - Usage: "Address of the syslog server to send Virtual Container Host logs to. Must be in the format transport://host[:port], where transport is udp or tcp. port defaults to 514 if not specified", - Destination: &s.SyslogAddr, - Hidden: true, - }, - } -} - -func (s *Syslog) ProcessSyslog() (*url.URL, error) { - if len(s.SyslogAddr) == 0 { - return nil, nil - } - - u, err := url.Parse(s.SyslogAddr) - if err != nil { - return nil, err - } - - return u, nil -} diff --git a/cmd/vic-machine/common/syslog_test.go b/cmd/vic-machine/common/syslog_test.go deleted file mode 100644 index 9646209cfe..0000000000 --- a/cmd/vic-machine/common/syslog_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019 VMware, 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 common - -import ( - "github.com/stretchr/testify/assert" - "testing" -) - -func TestProcessSysLog(t *testing.T) { - s := Syslog{} - s.SyslogAddr = "" - _, r := s.ProcessSyslog() - assert.Nil(t, r, "Should be nil, SyslogAddr is empty") -} diff --git a/cmd/vic-machine/configure/configure.go b/cmd/vic-machine/configure/configure.go index 23f55ada2c..b73b041d8d 100644 --- a/cmd/vic-machine/configure/configure.go +++ b/cmd/vic-machine/configure/configure.go @@ -52,9 +52,8 @@ type Configure struct { executor *management.Dispatcher - Force bool - help common.Help - Syslog common.Syslog + Force bool + help common.Help } func NewConfigure() *Configure { @@ -109,11 +108,10 @@ func (c *Configure) Flags() []cli.Flag { help := c.help.HelpFlags() squota := c.VCHStorageQuotaFlag() cvms := c.VCHContainerCountFlag() - syslog := c.Syslog.SyslogFlags() // flag arrays are declared, now combined var flags []cli.Flag - for _, f := range [][]cli.Flag{target, ops, id, compute, affinity, container, volume, dns, cNetwork, memory, cpu, squota, cvms, certificates, registries, proxies, syslog, util, debug, help} { + for _, f := range [][]cli.Flag{target, ops, id, compute, affinity, container, volume, dns, cNetwork, memory, cpu, squota, cvms, certificates, registries, proxies, util, debug, help} { flags = append(flags, f...) } @@ -163,12 +161,6 @@ func (c *Configure) processParams(op trace.Operation) error { } c.Data.RegistryCAs = c.registries.RegistryCAs - if u, err := c.Syslog.ProcessSyslog(); err == nil { - c.SyslogConfig.Addr = u - } else { - return err - } - return nil } @@ -269,10 +261,6 @@ func (c *Configure) copyChangedConf(o *config.VirtualContainerHostConfigSpec, n o.RegistryCertificateAuthorities = n.RegistryCertificateAuthorities } - if c.SyslogConfig.Addr != nil { - o.Diagnostics.SysLogConfig = n.Diagnostics.SysLogConfig - } - o.UseVMGroup = n.UseVMGroup if n.VMGroupName != "" { diff --git a/cmd/vic-machine/create/create.go b/cmd/vic-machine/create/create.go index 03915f4968..7056cb816b 100644 --- a/cmd/vic-machine/create/create.go +++ b/cmd/vic-machine/create/create.go @@ -67,7 +67,7 @@ type Create struct { Proxies common.Proxies - Syslog common.Syslog + SyslogAddr string executor *management.Dispatcher } @@ -252,6 +252,16 @@ func (c *Create) Flags() []cli.Flag { Usage: "Specify a list of permitted whitelist registry server addresses (insecure addresses still require the --insecure-registry option in addition)", }) + syslog := []cli.Flag{ + cli.StringFlag{ + Name: "syslog-address", + Value: "", + Usage: "Address of the syslog server to send Virtual Container Host logs to. Must be in the format transport://host[:port], where transport is udp or tcp. port defaults to 514 if not specified", + Destination: &c.SyslogAddr, + Hidden: true, + }, + } + util := []cli.Flag{ // miscellaneous cli.BoolFlag{ @@ -287,7 +297,6 @@ func (c *Create) Flags() []cli.Flag { help := c.help.HelpFlags() squota := c.VCHStorageQuotaFlag() cvms := c.VCHContainerCountFlag() - syslog := c.Syslog.SyslogFlags() // flag arrays are declared, now combined var flags []cli.Flag @@ -382,9 +391,7 @@ func (c *Create) ProcessParams(op trace.Operation) error { c.HTTPSProxy = sproxy c.NoProxy = nproxy - if u, err := c.Syslog.ProcessSyslog(); err == nil { - c.SyslogConfig.Addr = u - } else { + if err = c.ProcessSyslog(); err != nil { return err } @@ -521,6 +528,20 @@ func (c *Create) ProcessNetwork(op trace.Operation, network *data.NetworkConfig, return nil } +func (c *Create) ProcessSyslog() error { + if len(c.SyslogAddr) == 0 { + return nil + } + + u, err := url.Parse(c.SyslogAddr) + if err != nil { + return err + } + + c.SyslogConfig.Addr = u + return nil +} + func (c *Create) logArguments(op trace.Operation, cliContext *cli.Context) []string { args := []string{} sf := c.SetFields() // StringSlice options set by the user diff --git a/cmd/vic-machine/create/create_test.go b/cmd/vic-machine/create/create_test.go index e257db88ad..87788621d5 100644 --- a/cmd/vic-machine/create/create_test.go +++ b/cmd/vic-machine/create/create_test.go @@ -99,3 +99,10 @@ func TestSetFields(t *testing.T) { option := c.SetFields() assert.NotNil(t, option) } + +func TestProcessSysLog(t *testing.T) { + c := NewCreate() + c.SyslogAddr = "" + r := c.ProcessSyslog() + assert.Nil(t, r, "Should be nil, SyslogAddr is empty") +} diff --git a/lib/apiservers/service/restapi/handlers/vch_create.go b/lib/apiservers/service/restapi/handlers/vch_create.go index b6b4624b7c..63af7652bf 100644 --- a/lib/apiservers/service/restapi/handlers/vch_create.go +++ b/lib/apiservers/service/restapi/handlers/vch_create.go @@ -424,10 +424,8 @@ func (h *vchCreate) buildCreate(op trace.Operation, d *data.Data, finder client. } if vch.SyslogAddr != "" { - c.Syslog.SyslogAddr = vch.SyslogAddr.String() - if u, err := c.Syslog.ProcessSyslog(); err == nil { - c.SyslogConfig.Addr = u - } else { + c.SyslogAddr = vch.SyslogAddr.String() + if err := c.ProcessSyslog(); err != nil { return nil, errors.NewError(http.StatusBadRequest, "error processing syslog server address: %s", err) } } diff --git a/lib/apiservers/service/restapi/handlers/vch_create_test.go b/lib/apiservers/service/restapi/handlers/vch_create_test.go index a0419d989b..cf6f723124 100644 --- a/lib/apiservers/service/restapi/handlers/vch_create_test.go +++ b/lib/apiservers/service/restapi/handlers/vch_create_test.go @@ -204,7 +204,7 @@ func newCreate() *create.Create { InsecureRegistriesArg: cli.StringSlice{"https://insecure.example.com"}, WhitelistRegistriesArg: cli.StringSlice{"10.0.0.0/8"}, } - ca.Syslog = common.Syslog{"tcp://syslog.example.com:4444"} + ca.SyslogAddr = "tcp://syslog.example.com:4444" ca.ContainerNameConvention = "container-{id}" ca.Certs.CertPath = "test-vch" ca.Certs.NoSaveToDisk = true @@ -226,9 +226,6 @@ func compare(a, b reflect.Value, index int) (err error) { case reflect.Interface: return compare(a.Elem(), b.Elem(), index) case reflect.Struct: - if a.Type().Field(0).Name == "SyslogAddr" { - return nil - } for i := 0; i < a.NumField(); i++ { if err = compare(a.Field(i), b.Field(i), i); err != nil { fmt.Printf("Field name a: %s, b: %s, index: %d\n", a.Type().Field(i).Name, b.Type().Field(i).Name, i) diff --git a/lib/install/data/data.go b/lib/install/data/data.go index 57670a8062..9d4c8e1476 100644 --- a/lib/install/data/data.go +++ b/lib/install/data/data.go @@ -373,8 +373,6 @@ func (d *Data) CopyNonEmpty(src *Data) error { d.RegistryCAs = src.RegistryCAs - d.SyslogConfig = src.SyslogConfig - d.ContainerConfig.ContainerNameConvention = src.ContainerConfig.ContainerNameConvention return nil diff --git a/tests/test-cases/Group6-VIC-Machine/6-15-Syslog.robot b/tests/test-cases/Group6-VIC-Machine/6-15-Syslog.robot index 92296b1f4e..7fa60dc001 100644 --- a/tests/test-cases/Group6-VIC-Machine/6-15-Syslog.robot +++ b/tests/test-cases/Group6-VIC-Machine/6-15-Syslog.robot @@ -15,7 +15,8 @@ *** Settings *** Documentation Test 6-15 - Verify remote syslog Resource ../../resources/Util.robot -Test Teardown Cleanup VIC Appliance On Test Server +Suite Setup Install VIC Appliance To Test Server additional-args=--syslog-address tcp://%{SYSLOG_SERVER}:514 --debug 1 +Suite Teardown Cleanup VIC Appliance On Test Server Test Timeout 20 minutes *** Variables *** @@ -31,6 +32,7 @@ Get Remote PID Should Not Be Empty ${pid} [Return] ${pid} +*** Test Cases *** Verify VCH remote syslog # enable ssh ${output}= Run bin/vic-machine-linux debug --name=%{VCH-NAME} --target=%{TEST_URL} --thumbprint=%{TEST_THUMBPRINT} --user=%{TEST_USERNAME} --password=%{TEST_PASSWORD} @@ -96,27 +98,9 @@ Verify VCH remote syslog # Check trace logger for docker-engine and port-layer Should Match Regexp ${out} ${vch-ip} docker-engine-server\\[${pid}\\]: op=${pid}.\\d+: Commit container \\w{64} - #Should Match Regexp ${out} ${vch-ip} port-layer-server\\[${port-layer-pid}\\]: op=${port-layer-pid}.\\d+: Creating base file structure on disk + Should Match Regexp ${out} ${vch-ip} port-layer-server\\[${port-layer-pid}\\]: op=${port-layer-pid}.\\d+: Creating base file structure on disk Should Match Regexp ${out} ${vch-ip} vicadmin\\[${vic-admin-pid}\\]: op=${vic-admin-pid}.\\d+: vSphere resource cache populating... Should Match Regexp ${out} ${shortID} ${shortID}\\[1\\]: bin Should Match Regexp ${out} ${shortID} ${shortID}\\[1\\]: home Should Match Regexp ${out} ${shortID} ${shortID}\\[1\\]: var - - -*** Test Cases *** -Verify VCH Create remote syslog - - Install VIC Appliance To Test Server certs=${false} additional-args=--syslog-address tcp://%{SYSLOG_SERVER}:514 --debug 1 - - Verify VCH remote syslog - -Verify VCH Configure remote syslog - - Install VIC Appliance To Test Server certs=${false} additional-args=--debug 1 - - ${rc} ${output}= Run And Return Rc And Output bin/vic-machine-linux configure --target %{TEST_URL} --user %{TEST_USERNAME} --password=%{TEST_PASSWORD} --compute-resource=%{TEST_RESOURCE} --name %{VCH-NAME} --syslog-address tcp://%{SYSLOG_SERVER}:514 --thumbprint=%{TEST_THUMBPRINT} --debug 1 - Should Be Equal As Integers ${rc} 0 - Should Contain ${output} Completed successfully - - Verify VCH remote syslog