Skip to content

Commit

Permalink
test(connector-fabric): fix tests - package io/fs is not in GOROOT
Browse files Browse the repository at this point in the history
The simple answer was to upgrade to go v1.20.x from v1.15.x, but
this caused a series of other problems that also needed to address
so the complete list of changes and their motivations are below:

1. The upgrade to go v1.20.6
1.1. We no longer install docker-compose via pip because since v2
it ships with the main docker package itself (they rewrote it in go)
1.2. Added a new "gcompat" apk package which is necessary because
of go v1.20.6 as well. Details on this can be found here:
golang/go#59305 (comment)
1.3. As  part of installing the OpenSSH server, we now must first wipe all
openssh* packages due to newly surfaced package version conflicts due
to the ones that are prepackaged with the alpine image.
Without the purge step it fails like this:
    => ERROR [17/64] RUN apk add --no-cache openssh augeas                   1.1s
   ------
    > [17/64] RUN apk add --no-cache openssh augeas:
   0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
   0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
   1.041 ERROR: unable to select packages:
   1.043   openssh-client-common-9.3_p1-r3:
   1.043     breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
2. Upgraded the node-ssh library to v13 because v12 was broken due to
changes introduced by the new OpenSSH server.
3. Modified the container image definition so that we have the ability
to customize the version of fabric-nodeenv images used internally by the
peers of the fabric-samples repository. This was needed so that we can
control what version of npm and NodeJS are being used when the chain code
installation process is happening (which is just the peer running the
`npm install --production` command within the fabric-nodeenv container)
4. The default Fabric version used by the testing infrastructure is now
Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2
5. Slightly rearranged the imports & constants in some of the tests
which made it easier to verify that the new image is working as intended.
6. The new image built from this dockerfile for Fabric AIO 2.x is tagged
on the registry as:
`ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358`

Fixes hyperledger-cacti#2358

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Aug 11, 2023
1 parent a8e4d55 commit aa73552
Show file tree
Hide file tree
Showing 26 changed files with 398 additions and 1,223 deletions.
3 changes: 1 addition & 2 deletions packages/cactus-plugin-ledger-connector-corda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"express-openapi-validator": "3.10.0",
"internal-ip": "6.2.0",
"joi": "17.9.1",
"node-ssh": "12.0.0",
"node-ssh": "13.1.0",
"prom-client": "13.2.0",
"rxjs": "7.8.1",
"temp": "0.9.4",
Expand All @@ -73,7 +73,6 @@
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
"@types/express": "4.17.13",
"@types/multer": "1.4.7",
"@types/node-ssh": "7.0.1",
"@types/temp": "0.9.1",
"express": "4.17.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,10 @@
* More details: https://github.com/facebook/jest/pull/12789
*/

//////////////////////////////////
// Constants
//////////////////////////////////

// Ledger settings
const imageName = "ghcr.io/hyperledger/cactus-fabric2-all-in-one";
const imageVersion = "2021-09-02--fix-876-supervisord-retries";
const fabricEnvVersion = "2.2.0";
const fabricEnvCAVersion = "1.4.9";
const ledgerUserName = "appUser";
const ledgerChannelName = "mychannel";
const ledgerContractName = "basic";
const leaveLedgerRunning = false; // default: false
const useRunningLedger = false; // default: false

// Log settings
const testLogLevel: LogLevelDesc = "info"; // default: info
const sutLogLevel: LogLevelDesc = "info"; // default: info

import {
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
SelfSignedPkiGenerator,
Expand Down Expand Up @@ -61,6 +45,25 @@ import os from "os";
import "jest-extended";
import { Server as HttpsServer } from "https";

//////////////////////////////////
// Constants
//////////////////////////////////

// Ledger settings
const imageName = DEFAULT_FABRIC_2_AIO_IMAGE_NAME;
const imageVersion = DEFAULT_FABRIC_2_AIO_IMAGE_VERSION;
const fabricEnvVersion = DEFAULT_FABRIC_2_AIO_FABRIC_VERSION;
const fabricEnvCAVersion = "1.4.9";
const ledgerUserName = "appUser";
const ledgerChannelName = "mychannel";
const ledgerContractName = "basic";
const leaveLedgerRunning = false; // default: false
const useRunningLedger = false; // default: false

// Log settings
const testLogLevel: LogLevelDesc = "debug"; // default: info
const sutLogLevel: LogLevelDesc = "debug"; // default: info

// Logger setup
const log: Logger = LoggerProvider.getOrCreate({
label: "fabric-socketio-connector.test",
Expand Down Expand Up @@ -203,7 +206,7 @@ describe("Fabric-SocketIO connector tests", () => {
useRunningLedger,
});
log.debug("Fabric image:", ledger.getContainerImageName());
await ledger.start();
await ledger.start({ omitPull: false });

// Get connection profile
log.info("Get fabric connection profile for Org1...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"jsrsasign": "10.5.25",
"multer": "1.4.5-lts.1",
"ngo": "2.7.0",
"node-ssh": "12.0.0",
"node-ssh": "13.1.0",
"node-vault": "0.9.22",
"openapi-types": "9.1.0",
"prom-client": "13.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SSHExecCommandResponse } from "node-ssh";
import { RuntimeError } from "run-time-error";

export function isSshExecOk(res: SSHExecCommandResponse): boolean {
const fnTag = "isSshExecOk()";
if (!res) {
throw new RuntimeError(`${fnTag} expected arg res to be truthy.`);
}
return res.code === null || res.code === 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";

import { Certificate } from "@fidm/x509";
import { Express } from "express";
import { RuntimeError } from "run-time-error";
import "multer";
import temp from "temp";
import {
Expand Down Expand Up @@ -123,6 +124,7 @@ import {
} from "./common/get-transaction-receipt-by-tx-id";
import { GetBlockEndpointV1 } from "./get-block/get-block-endpoint-v1";
import { querySystemChainCode } from "./common/query-system-chain-code";
import { isSshExecOk } from "./common/is-ssh-exec-ok";

/**
* Constant value holding the default $GOPATH in the Fabric CLI container as
Expand All @@ -148,6 +150,7 @@ export interface IPluginLedgerConnectorFabricOptions
cliContainerEnv: NodeJS.ProcessEnv;
pluginRegistry: PluginRegistry;
sshConfig: SshConfig;
readonly sshDebugOn?: boolean;
connectionProfile: ConnectionProfile;
prometheusExporter?: PrometheusExporter;
discoveryOptions?: GatewayDiscoveryOptions;
Expand Down Expand Up @@ -178,6 +181,7 @@ export class PluginLedgerConnectorFabric
private endpoints: IWebServiceEndpoint[] | undefined;
private readonly secureIdentity: SecureIdentityProviders;
private readonly certStore: CertDatastore;
private readonly sshDebugOn: boolean;
private runningWatchBlocksMonitors = new Set<WatchBlocksV1Endpoint>();

public get className(): string {
Expand Down Expand Up @@ -225,6 +229,11 @@ export class PluginLedgerConnectorFabric
webSocketConfig: opts.webSocketConfig,
});
this.certStore = new CertDatastore(opts.pluginRegistry);

this.sshDebugOn = opts.sshDebugOn === true;
if (this.sshDebugOn) {
this.opts.sshConfig = this.enableSshDebugLogs(this.opts.sshConfig);
}
}

public getOpenApiSpec(): unknown {
Expand Down Expand Up @@ -268,6 +277,16 @@ export class PluginLedgerConnectorFabric

return consensusHasTransactionFinality(currentConsensusAlgorithmFamily);
}

private enableSshDebugLogs(cfg: SshConfig): SshConfig {
const fnTag = `${this.className}#decorateSshConfigWithLogger()`;
Checks.truthy(cfg, `${fnTag} cfg must be truthy.`);
return {
...cfg,
debug: (msg: unknown) => this.log.debug(`[NodeSSH] %o`, msg),
};
}

private async sshExec(
cmd: string,
label: string,
Expand All @@ -276,8 +295,13 @@ export class PluginLedgerConnectorFabric
): Promise<SSHExecCommandResponse> {
this.log.debug(`${label} CMD: ${cmd}`);
const cmdRes = await ssh.execCommand(cmd, sshCmdOptions);
this.log.debug(`${label} CMD Response: %o`, cmdRes);
Checks.truthy(cmdRes.code === null, `${label} cmdRes.code === null`);
this.log.debug(`${label} CMD Response .code: %o`, cmdRes.code);
this.log.debug(`${label} CMD Response .signal: %o`, cmdRes.signal);
this.log.debug(`${label} CMD Response .stderr: %s`, cmdRes.stderr);
this.log.debug(`${label} CMD Response .stdout: %s`, cmdRes.stdout);
if (cmdRes.code !== null && cmdRes.code !== 0) {
throw new RuntimeError(`Expected ${label} cmdRes.code as null or 0`);
}
return cmdRes;
}

Expand All @@ -292,7 +316,10 @@ export class PluginLedgerConnectorFabric
const { log, opts } = this;

const ssh = new NodeSSH();
this.log.debug(`${fnTag} Establishing SSH connection to peer...`);
await ssh.connect(opts.sshConfig);
this.log.debug(`${fnTag} Established SSH connection to peer OK.`);

if (req.collectionsConfigFile) {
log.debug(`Has private data collection definition`);
}
Expand Down Expand Up @@ -569,7 +596,7 @@ export class PluginLedgerConnectorFabric
{
const res = await this.sshExec(commitCmd, "Commit", ssh, sshCmdOptions);
lifecycle.commit = res;
success = success && res.code === null;
success = success && isSshExecOk(res);
}

{
Expand Down Expand Up @@ -781,7 +808,7 @@ export class PluginLedgerConnectorFabric
);

log.debug(`Instantiate CMD Response:%o`, instantiationCommandResponse);
success = success && instantiationCommandResponse.code === null;
success = success && isSshExecOk(instantiationCommandResponse);

log.debug(`EXIT doDeploy()`);
const res: DeployContractGoSourceV1Response = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
module github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go

go 1.13
go 1.18

require (
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-contract-api-go v1.1.0
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect
github.com/go-openapi/jsonreference v0.19.4 // indirect
github.com/go-openapi/spec v0.19.8 // indirect
github.com/go-openapi/swag v0.19.9 // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-contract-api-go v1.1.0
github.com/gobuffalo/packr v1.30.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/rogpeppe/go-internal v1.6.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading

0 comments on commit aa73552

Please sign in to comment.