Skip to content

Commit 866b6fb

Browse files
mbraseCQ Bot
authored andcommitted
Revert "Reland "[orchestrate][repo] Orchestrate adopting standalone package server""
This reverts commit e5b843e. Reason for revert: Broke google3 use of orchestrate b/377925487. Original change's description: > Reland "[orchestrate][repo] Orchestrate adopting standalone package server" > > This is a reland of commit 8b2b5d1 > > The revert was due to a broken dependency in //tools/docsgen which was addressed in fxr/1148896. > > This changes orchestrate to use the standalone repository package server. > > Bug: 374085877 > Change-Id: Id63135503a802f2f2b8ac2a16068ca0e2bf5321f > Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1152331 > Reviewed-by: Darren Chan <[email protected]> > Commit-Queue: Clayton Wilkinson <[email protected]> Bug: 374085877, 377925487 Change-Id: Ida589d36e592602fe76011652b8a88f2aa3b1edb No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1153234 Commit-Queue: Michael Brase <[email protected]> Reviewed-by: RubberStamper 🤖 <[email protected]>
1 parent 12c39b4 commit 866b6fb

File tree

3 files changed

+30
-105
lines changed

3 files changed

+30
-105
lines changed

tools/orchestrate/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ go_binary("orchestrate") {
7272
sdk_host_tool("orchestrate_sdk") {
7373
category = "partner"
7474
output_name = "orchestrate"
75-
deps = [ ":orchestrate" ]
75+
deps = [ "//tools/orchestrate" ]
7676
}
7777

7878
group("tests") {

tools/orchestrate/ffx/ffx.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@ import (
2121
utils "go.fuchsia.dev/fuchsia/tools/orchestrate/utils"
2222
)
2323

24-
type pathType struct {
25-
File string `json:"file"`
26-
URL string `json:"url"`
27-
}
28-
29-
type repoServerList struct {
30-
Result struct {
31-
Data []struct {
32-
Name string `json:"name"`
33-
Address string `json:"address"`
34-
RepoPath pathType `json:"repo_path"`
35-
RegistrationAliases []string `json:"registration_aliases"`
36-
RegistrationStorageType string `json:"registration_storage_type"`
37-
RegistrationAliasConflictMode string `json:"registration_alias_conflict_mode"`
38-
ServerMode string `json:"server_mode"`
39-
PID int `json:"pid"`
40-
} `json:"data"`
41-
} `json:"ok"`
42-
}
43-
4424
// XDG_ENV_VARS are leaky environment variables to override. See ApplyEnv.
4525
var XDG_ENV_VARS = [...]string{
4626
"HOME",
@@ -318,26 +298,3 @@ func writeConfigFile(configPath string, opt Option, socketPath string) error {
318298
}
319299
return nil
320300
}
321-
322-
// isRunning returns true if the package server is currently running and responds to HTTP requests.
323-
func (f *Ffx) IsPackageServerRunning(repoName string) (bool, error) {
324-
325-
args := []string{"--machine", "json", "repository", "server", "list"}
326-
out, err := f.RunCmdSync(args...)
327-
if err != nil {
328-
return false, fmt.Errorf("ffx repository server list: output: %s, error: %w", out, err)
329-
}
330-
var repoList repoServerList
331-
if err := json.Unmarshal([]byte(out), &repoList); err != nil {
332-
return false, err
333-
}
334-
repoNamePrefix := fmt.Sprintf("%s.", repoName)
335-
for _, status := range repoList.Result.Data {
336-
// product bundle based repo servers use the repoName as a prefix.
337-
if status.Name == repoName || strings.HasPrefix(status.Name, repoNamePrefix) {
338-
return true, nil
339-
}
340-
}
341-
// We don't need to differentiate between a stopped package server, no server found, etc.
342-
return false, nil
343-
}

tools/orchestrate/orchestrator.go

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"io"
12+
"net/http"
1213
"os"
1314
"os/exec"
1415
"path/filepath"
@@ -25,7 +26,6 @@ type TestOrchestrator struct {
2526
deviceConfig *DeviceConfig
2627
ffxLogProc *os.Process
2728
targetLogFile *os.File
28-
repoName string
2929
}
3030

3131
var (
@@ -41,7 +41,6 @@ var (
4141
func NewTestOrchestrator(deviceConfig *DeviceConfig) *TestOrchestrator {
4242
return &TestOrchestrator{
4343
deviceConfig: deviceConfig,
44-
repoName: fmt.Sprintf("repo-%d", os.Getpid()),
4544
}
4645
}
4746

@@ -172,27 +171,12 @@ func (r *TestOrchestrator) setupFfx() error {
172171
{"config", "set", "daemon.autostart", "false"},
173172
{"config", "set", "overnet.cso", "only"},
174173
{"config", "set", "ffx-repo-add", "true"},
175-
// Set a unique repository server name for this run.
176-
{"config", "set", "repository.default", r.repoName},
177-
// Disable the daemon based repo server.
178-
{"config", "set", "repository.server.enabled", "false"},
179174
}
180-
181175
for _, cmd := range cmds {
182176
if out, err := r.ffx.RunCmdSync(cmd...); err != nil {
183177
return fmt.Errorf("ffx setup %v: %w out: %s", cmd, err, out)
184178
}
185179
}
186-
187-
// If there is a log dir, set it instead of the default
188-
log_dir := os.Getenv("TEST_UNDECLARED_OUTPUTS_DIR")
189-
if log_dir != "" {
190-
cmd := []string{"config", "set", "log.dir", log_dir}
191-
if out, err := r.ffx.RunCmdSync(cmd...); err != nil {
192-
return fmt.Errorf("ffx setup %v: %w out: %s", cmd, err, out)
193-
}
194-
}
195-
196180
if err := r.dumpFfxConfig(); err != nil {
197181
return fmt.Errorf("dumpFfxConfig: %w", err)
198182
}
@@ -289,20 +273,10 @@ func (r *TestOrchestrator) startEmulator(productDir string) error {
289273
}
290274

291275
/* Step 4 - Serving packages. */
292-
/*
293-
Serving packages requires:
294-
* Creating the package repository or having a downloaded product bundle.
295-
* Publishing a package to make sure the metadata is up to date. (Can we use --refresh metadata instead?)
296-
* Starting the package server process
297-
* Registering the package server on the target device.
298-
* Package servers are managed by name. or if using product bundles, the product bundle directory.
299-
300-
*/
301276
func (r *TestOrchestrator) servePackages(in *RunInput, productDir string) error {
302-
if err := r.serveAndWait(productDir); err != nil {
303-
return fmt.Errorf("serveAndWait: %w", err)
277+
if out, err := r.ffx.RunCmdSync("repository", "add-from-pm", productDir); err != nil {
278+
return fmt.Errorf("ffx repository add-from-pm: %w out: %s", err, out)
304279
}
305-
306280
// It is important to always publish, even if there is nothing in
307281
// in.Target().PackageArchives, because it will force the package metadata
308282
// to be refreshed (see b/309847820).
@@ -318,41 +292,39 @@ func (r *TestOrchestrator) servePackages(in *RunInput, productDir string) error
318292
return fmt.Errorf("ffx debug symbol-index add %s: %w out: %s", buildID, err, out)
319293
}
320294
}
321-
322-
if _, err := r.ffx.RunCmdSync("repository", "server", "list"); err != nil {
323-
return fmt.Errorf("ffx repository server list: %w", err)
295+
if err := r.serveAndWait(); err != nil {
296+
return fmt.Errorf("serveAndWait: %w", err)
297+
}
298+
if _, err := r.ffx.RunCmdSync("repository", "list"); err != nil {
299+
return fmt.Errorf("ffx repository list: %w", err)
324300
}
325301
return nil
326302
}
327303

328-
func (r *TestOrchestrator) serveAndWait(productDir string) error {
304+
func (r *TestOrchestrator) serveAndWait() error {
329305
port := os.Getenv("FUCHSIA_PACKAGE_SERVER_PORT")
330306
if port == "" {
331-
// Use a dynamic port unless the environment is specific.
332-
port = "0"
307+
port = "8083"
333308
}
334309
addr := fmt.Sprintf("[::]:%s", port)
335-
args := []string{
336-
"repository", "server", "start",
337-
"--background", "--no-device",
338-
"--address", addr,
339-
"--product-bundle", productDir,
340-
"--repository", r.repoName,
341-
}
342-
if _, err := r.ffx.RunCmdSync(args...); err != nil {
310+
if _, err := r.ffx.RunCmdAsync("repository", "server", "start", "--address", addr); err != nil {
343311
return fmt.Errorf("ffx repository server start: %w", err)
344312
}
345-
346-
// The server start command when using `--background` waits for the server
347-
// to actually start before exiting, so this check is a double check.
348-
running, err := r.ffx.IsPackageServerRunning(r.repoName)
349-
if err != nil {
350-
return fmt.Errorf("ffx isPackageServerRunning: %w", err)
351-
}
352-
if !running {
353-
return fmt.Errorf("repository %s is not running", r.repoName)
354-
}
355-
return nil
313+
return utils.RunWithRetries(context.Background(), 500*time.Millisecond, 5, func() error {
314+
req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost:%s", port), nil)
315+
if err != nil {
316+
return fmt.Errorf("http.NewRequest: %w", err)
317+
}
318+
resp, err := http.DefaultClient.Do(req)
319+
if err != nil {
320+
return fmt.Errorf("http.DefaultClient.Do: %w", err)
321+
}
322+
// Check the response status code
323+
if resp.StatusCode != 200 {
324+
return fmt.Errorf("resp.StatusCode: got %d, want 200", resp.StatusCode)
325+
}
326+
return nil
327+
})
356328
}
357329

358330
/* Step 5 - Reach Device */
@@ -363,7 +335,6 @@ func (r *TestOrchestrator) reachDevice() error {
363335
return fmt.Errorf("ffx target add: %w", err)
364336
}
365337
}
366-
367338
if _, err := r.ffx.RunCmdSync("target", "wait"); err != nil {
368339
return fmt.Errorf("ffx target wait: %w", err)
369340
}
@@ -373,19 +344,16 @@ func (r *TestOrchestrator) reachDevice() error {
373344
if err := r.dumpFfxLog(); err != nil {
374345
return fmt.Errorf("dumpFfxLog: %w", err)
375346
}
376-
377-
// Register the repo server using the aliases configured with the running server.
378347
if out, err := r.ffx.RunCmdSync(
379348
"target",
380349
"repository",
381350
"register",
382351
"--repository",
383-
r.repoName,
352+
"devhost",
384353
"--alias",
385354
"fuchsia.com",
386355
"--alias",
387-
"chromium.org",
388-
); err != nil {
356+
"chromium.org"); err != nil {
389357
return fmt.Errorf("ffx target repository register: %w out: %s", err, out)
390358
}
391359
return nil
@@ -513,7 +481,7 @@ func writeJSON(filename string, data any) error {
513481

514482
/* Cleanup */
515483
func (r *TestOrchestrator) stopPackageServer() {
516-
if _, err := r.ffx.RunCmdSync("repository", "server", "stop", r.repoName); err != nil {
484+
if _, err := r.ffx.RunCmdSync("repository", "server", "stop"); err != nil {
517485
fmt.Printf("ffx repository server stop: %v", err)
518486
}
519487
}

0 commit comments

Comments
 (0)