Skip to content

Commit

Permalink
Merge pull request #959 from golemfactory/bump-ya-ts-client-to-1.1.1
Browse files Browse the repository at this point in the history
Bump ya-ts-client to 1.1.2 (fix network interface)
  • Loading branch information
SewerynKras authored Jun 18, 2024
2 parents aa52ffa + c7bdf27 commit bfd958a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 36 deletions.
12 changes: 2 additions & 10 deletions src/experimental/deployment/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,14 @@ describe("Deployment builder", () => {
it("throws an error when creating a network with the same name", () => {
const builder = new GolemDeploymentBuilder(mockGolemNetwork);
expect(() => {
builder
.createNetwork("my-network", {
id: "test",
})
.createNetwork("my-network", {
id: "test",
});
builder.createNetwork("my-network").createNetwork("my-network");
}).toThrow(new GolemConfigError(`Network with name my-network already exists`));
});
it("throws an error when creating a deployment with an activity pool referencing a non-existing network", () => {
const builder = new GolemDeploymentBuilder(mockGolemNetwork);
expect(() => {
builder
.createNetwork("existing-network", {
id: "test",
})
.createNetwork("existing-network")
.createLeaseProcessPool("my-pool", {
demand: {
workload: { imageTag: "image", minCpuCores: 1, minMemGib: 1, minStorageGib: 1 },
Expand Down
2 changes: 1 addition & 1 deletion src/experimental/deployment/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class GolemDeploymentBuilder {
return this;
}

createNetwork(name: string, options: NetworkOptions): this {
createNetwork(name: string, options: NetworkOptions = {}): this {
if (this.components.networks.some((network) => network.name === name)) {
throw new GolemConfigError(`Network with name ${name} already exists`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class GolemNetwork {
marketApi:
this.options.override?.marketApi ||
new MarketApiAdapter(this.yagna, agreementRepository, proposalRepository, demandRepository, this.logger),
networkApi: this.options.override?.networkApi || new NetworkApiAdapter(this.yagna, this.logger),
networkApi: this.options.override?.networkApi || new NetworkApiAdapter(this.yagna),
fileServer: this.options.override?.fileServer || new GftpServerAdapter(this.storageProvider),
};
this.network = getFactory(NetworkModuleImpl, this.options.override?.network)(this.services);
Expand Down
13 changes: 4 additions & 9 deletions src/network/network.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,37 @@ describe("Network", () => {
});

it("should create network with 16 bit mask", async () => {
await networkModule.createNetwork({ id: "1", ip: "192.168.7.0/16" });
await networkModule.createNetwork({ ip: "192.168.7.0/16" });
expect(capture(mockNetworkApi.createNetwork).last()).toEqual([
{
id: "1",
ip: "192.168.0.0",
mask: "255.255.0.0",
},
]);
});

it("should create network with 24 bit mask", async () => {
await networkModule.createNetwork({ id: "1", ip: "192.168.7.0/24" });
await networkModule.createNetwork({ ip: "192.168.7.0/24" });
expect(capture(mockNetworkApi.createNetwork).last()).toEqual([
{
id: "1",
ip: "192.168.7.0",
mask: "255.255.255.0",
},
]);
});

it("should create network with 8 bit mask", async () => {
await networkModule.createNetwork({ id: "1", ip: "192.168.7.0/8" });
await networkModule.createNetwork({ ip: "192.168.7.0/8" });
expect(capture(mockNetworkApi.createNetwork).last()).toEqual([
{
id: "1",
ip: "192.0.0.0",
mask: "255.0.0.0",
},
]);
});

it("should not create network with invalid ip", async () => {
const shouldFail = networkModule.createNetwork({ id: "1", ip: "123.1.2" });
const shouldFail = networkModule.createNetwork({ ip: "123.1.2" });
await expect(shouldFail).rejects.toMatchError(
new GolemNetworkError(
"Unable to create network. An IP4 number cannot have less or greater than 4 octets",
Expand All @@ -95,12 +92,10 @@ describe("Network", () => {
it("should create network with custom gateway", async () => {
await networkModule.createNetwork({
ip: "192.168.0.1/27",
id: "owner_1",
gateway: "192.168.0.2",
});
expect(capture(mockNetworkApi.createNetwork).last()).toEqual([
{
id: "owner_1",
ip: "192.168.0.0",
mask: "255.255.255.224",
gateway: "192.168.0.2",
Expand Down
9 changes: 1 addition & 8 deletions src/network/network.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ import AsyncLock from "async-lock";
import { getMessageFromApiError } from "../shared/utils/apiErrorMessage";

export interface NetworkOptions {
/**
* The ID of the network.
* This is an optional field that can be used to specify a unique identifier for the network.
* If not provided, it will be generated automatically.
*/
id?: string;

/**
* The IP address of the network. May contain netmask, e.g. "192.168.0.0/24".
* This field can include the netmask directly in CIDR notation.
* @default "192.168.0.0"
*/
ip?: string;

Expand Down Expand Up @@ -99,7 +93,6 @@ export class NetworkModuleImpl implements NetworkModule {
const mask = ipRange.getPrefix().toMask();
const gateway = options?.gateway ? new IPv4(options.gateway) : undefined;
const network = await this.networkApi.createNetwork({
id: options?.id,
ip: ip.toString(),
mask: mask?.toString(),
gateway: gateway?.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/shared/yagna/adapters/market-api-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export class MarketApiAdapter implements IMarketApi {
receivedProposal.id,
bodyClone,
);

this.logger.debug("Proposal counter result from yagna", { result: maybeNewId });

if (typeof maybeNewId !== "string") {
Expand Down
8 changes: 2 additions & 6 deletions src/shared/yagna/adapters/network-api-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { YagnaApi } from "../yagnaApi";
import { Logger } from "../../utils";
import { GolemNetworkError, INetworkApi, Network, NetworkErrorCode, NetworkNode } from "../../../network";
import { getMessageFromApiError } from "../../utils/apiErrorMessage";

export class NetworkApiAdapter implements INetworkApi {
constructor(
private readonly yagnaApi: YagnaApi,
private readonly logger: Logger,
) {}
constructor(private readonly yagnaApi: YagnaApi) {}

async createNetwork(options: { id: string; ip: string; mask?: string; gateway?: string }): Promise<Network> {
async createNetwork(options: { ip: string; mask?: string; gateway?: string }): Promise<Network> {
try {
const { id, ip, mask, gateway } = await this.yagnaApi.net.createNetwork(options);
return new Network(id, ip, mask, gateway);
Expand Down

0 comments on commit bfd958a

Please sign in to comment.