You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/07/13 19:53:52 UTC

[GitHub] [trafficcontrol] traeak opened a new pull request, #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

traeak opened a new pull request, #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #ISSUE
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   
   Current t3c internall hard codes t3c-generate to /usr/bin/t3c-generate and does a path lookup when calling other t3c-* utilities.
   
   This PR uses a vendored osext library to pull the executable directory path and looks only there when calling any t3c-* sub programs.
   
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   - Traffic Control Cache Config (`t3c`, formerly ORT)
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your PR.
   If your PR has tests (and most should), provide the steps needed to run the tests.
   If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
   
   Ensure t3c still runs as installed.
   
   Make the t3c package, install t3c, copy out the binaries to another directory not in path, run t3c via path and ensure it works.
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
   Examples:
   - 5.1.2
   - 5.1.3 (RC1)
    -->
   
   
   ## PR submission checklist
   - [ ] This PR has tests - already captured with normal t3c runs.
   - [ ] This PR has documentation - minor under the hood change.
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c merged pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

Posted by GitBox <gi...@apache.org>.
rob05c merged PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

Posted by GitBox <gi...@apache.org>.
rob05c commented on code in PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962#discussion_r930471104


##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -43,18 +44,31 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+const (
+	t3cgen       = `t3c generate`
+	t3cupd       = `t3c update`
+	t3cdiff      = `t3c diff`
+	t3cchkrefs   = `t3c check refs`
+	t3cchkreload = `t3c check relaod`

Review Comment:
   Typo "reload"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

Posted by GitBox <gi...@apache.org>.
rob05c commented on code in PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962#discussion_r930472577


##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -531,17 +551,18 @@ func requestConfig(cfg config.Cfg) ([]byte, error) {
 	stdOut := ([]byte)(nil)
 	stdErr := ([]byte)(nil)
 	code := 0
+	t3cpath := filepath.Join(t3cutil.InstallDir(), `t3c`)
 	if len(cacheBts) > 0 {
-		stdOut, stdErr, code = t3cutil.DoInput(cacheBts, `t3c`, args...)
+		stdOut, stdErr, code = t3cutil.DoInput(cacheBts, t3cpath, args...)
 	} else {
-		stdOut, stdErr, code = t3cutil.Do(`t3c`, args...)
+		stdOut, stdErr, code = t3cutil.Do(t3cpath, args...)
 	}
 	if code != 0 {
-		logSubAppErr(`t3c-request stdout`, stdOut)
-		logSubAppErr(`t3c-request stderr`, stdErr)
-		return nil, fmt.Errorf("t3c-request returned non-zero exit code %v, see log for details", code)
+		logSubAppErr(`t3c stdout`, stdOut)
+		logSubAppErr(`t3c stderr`, stdErr)
+		return nil, fmt.Errorf("t3c returned non-zero exit code %v, see log for details", code)
 	}
-	logSubApp(`t3c-request`, stdErr)
+	logSubApp(`t3c`, stdErr)

Review Comment:
   Looks like this should be `logSubApp(t3creq, stdErr)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] traeak commented on a diff in pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

Posted by GitBox <gi...@apache.org>.
traeak commented on code in PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962#discussion_r929046478


##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -85,7 +86,8 @@ func generate(cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) {
 	args = append(args, "--disable-parent-config-comments="+strconv.FormatBool(cfg.DisableParentConfigComments))
 	args = append(args, "--use-strategies="+cfg.UseStrategies.String())
 
-	generatedFiles, stdErr, code := t3cutil.DoInput(configData, config.GenerateCmd, args...)
+	genpath := filepath.Join(t3cutil.InstallDirectory(), config.GenerateCmd)

Review Comment:
   did as suggested within t3c-apply/torequest/cmd.go



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6962: t3c to look for t3c-generate and other t3c- apps in executable directory

Posted by GitBox <gi...@apache.org>.
rob05c commented on code in PR #6962:
URL: https://github.com/apache/trafficcontrol/pull/6962#discussion_r923645628


##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {
+	installdir, err := osext.ExecutableFolder()
+	if err != nil {
+		installdir = "/usr/bin"

Review Comment:
   Mind putting this in a global const? Just so it's easier to see, change, etc.



##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {

Review Comment:
   Would you object to naming this `InstallDir` instead? Kind of a nitpick, but it's a slightly bigger deal because of how frequently this is used. 
   
   Idiomatic Go prefers shorter names. Personally, I like to use the shortest abbreviation that's obvious and unambiguous. But I don't feel _that_ strongly about it, if you disagree.



##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -85,7 +86,8 @@ func generate(cfg config.Cfg) ([]t3cutil.ATSConfigFile, error) {
 	args = append(args, "--disable-parent-config-comments="+strconv.FormatBool(cfg.DisableParentConfigComments))
 	args = append(args, "--use-strategies="+cfg.UseStrategies.String())
 
-	generatedFiles, stdErr, code := t3cutil.DoInput(configData, config.GenerateCmd, args...)
+	genpath := filepath.Join(t3cutil.InstallDirectory(), config.GenerateCmd)

Review Comment:
   So, this is used in a bunch of places, basically every sub-app call.
   
   If you changed them all to use the `t3c` wrapper, e.g. `t3c generate` instead of `t3c-generate`, you could avoid all the duplication, put this in a global var, `var t3cPath = filepath.Join(t3cutil.InstallDir() + "t3c")`, and then all the args would just start with the sub-app, e.g.
   ```
   args := []string{"preprocess"}
   args += ...
   cmd := exec.Command(t3cPath, args...)
   ```



##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -228,3 +232,14 @@ func UserAgentStr(appName string, versionNum string, gitRevision string) string
 	}
 	return appName + "/" + versionNum + ".." + gitRevision
 }
+
+// InstallDirectory returns the location of the executable directory.
+// If error, returns "/usr/bin" as default.
+func InstallDirectory() string {
+	installdir, err := osext.ExecutableFolder()

Review Comment:
   ATC is on Go >1.18 which has `os.Executable()`. Can you change this to `os.Executable`, and not use/vendor `osext`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org